0

Im trying to pass a php variable, which is created from a form, to a url/ for use on another page. I might be going about it the completely wrong way, Im not sure.

//THE FORM

<form><input style="height:35px; width:520px; font-family:Arial, Helvetica, sans-serif; font-size:24px; text-align:center;" type="text" name="fbid" /></form>

//PHP TO GET THE TEXT FROM THE TEXT INPUT BOX

<?php
$id = $_GET['fbid'];
?>

//THE IMAGE/BUTTON THAT SENDS THE USER TO THE VARIABLE URL

<img src="images/FacebookSite_32.gif" width="333" height="59" alt="" onclick="location.href='page.php?id=<?php echo $id; ?>'">

So, I'm trying to get the text that was typed in the text input box, and pass it to the URL, for use on another page. Thanks for any help!

3
  • Hmm, I think you may do it wrong. Larger inputs should be passed via POST request (they may easily exceed URL max length). Then you can parse the text on server side and either display something, or make a redirect to the site with 'Cleaned up' URL. Also, I don't see any submit button in your form (deleted for simplicity?) Commented May 19, 2012 at 10:43
  • how are you supposed to get value w/o submitting the form ?? Commented May 19, 2012 at 10:53
  • Thanks for the reply - The text they input will be Max 25 characters, so I don't think it will exceed Max URL length. I would like the 'submit' to be in the '//THE IMAGE/BUTTON THAT SENDS THE USER TO THE VARIABLE URL'' like in the example. Sorry i'm a complete noob and didn't even realise there had to be one! Commented May 19, 2012 at 10:57

3 Answers 3

1

PHP runs on the server, so by the time the user sees the form the PHP will have already run and put an empty string into your javascript.

You might be better off just using javascript for this:

<form>
    <input style="some style stuff here..." type="text" name="fbid" />
</form>

<img src="images/FacebookSite_32.gif" width="333" height="59"
     onclick="location.href='page.php?id='+document.forms[0].elements[0].value" />

This code assumes that there is only one form on the page and that the value you want is in the first (0th) element.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much man! works perfectly and was just what I wanted!
0

Try this:

   <form action="<?php echo $_SERVER['PHP_SELF']; ?>" methode="GET" > 
  <input style="height:35px; width:520px; font-family:Arial, Helvetica, sans-serif; font-size:24px; text-align:center;" type="text" name="fbid" />
  <input type="submit" value="submit" name="submit" />
    </form>

<?php

if(isset($_GET['fbid'])){
   $id = $_GET['fbid'];
   echo $id;
 }
   ?>

Comments

0

Try this:

//THE FORM

<form action="" method="GET">
<input style="height:35px; width:520px; font-family:Arial, Helvetica, sans-serif; font-size:24px; text-align:center;" type="text" name="fbid" />
<input type="submit">
</form>

//PHP TO GET THE TEXT FROM THE TEXT INPUT BOX

<?php
$id = (int)$_GET['fbid'];
?>

//THE IMAGE/BUTTON THAT SENDS THE USER TO THE VARIABLE URL

<img src="images/FacebookSite_32.gif" width="333" height="59" alt="" onclick="location.href='page.php?id=<?php echo $id ?>'">

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.