Jump to content

PHP Variables


Howdy_McGee

Recommended Posts

I have a form going right - using _POST method. Like so:

$name = $_POST['name'];

I want to retrieve that variable in another webpage to display their name. The code is in an External PHP File. If The 'Captcha' is wrong the email won't be sent and I would assume the information would still be held in the variables. What I want to do is Grab the content of these variables and redisplay them so they don't have to retype their data. How do I do this?

Link to comment
Share on other sites

You would make the value of the text input the post value of that field:

<input type="text" name="name" value="<?php echo $_POST['name']; ?>" />

Now this will actually give you an error unless the $_POST variable is defined. I wrote a little function to fix this:

function post_default($var) {$var = isset($var) ? $var : '';return $var;}

You can use it like this:

<input type="text" name="name" value="<?php echo post_default($_POST['name']); ?>" />

Link to comment
Share on other sites

Do you have your form setup where it goes from the form page to the processing page?As in, the form is on form.php and when you press submit, it goes to process.php?If so, then you should check the input of the CAPTCHA first and send them immediately back to the form page if the input was incorrect.@FMDPA, when would the $_POST variable ever be undefined? If a form with post data is sent, isn't it always set?

Link to comment
Share on other sites

when would the $_POST variable ever be undefined? If a form with post data is sent, isn't it always set?
in this case when you will call the page first it will dont have the value in $_POST so it will raise a error notice. it will hold value after being submited.
value="<?php echo $_POST['name']; ?>
Link to comment
Share on other sites

would that work if this is a separate page than what the original form is on?
The function I posted must be on the same page as the text input. Well, you could use the require function, and put the function in a separate file. Another alternative would be to use the function inline:
<input type="text" name="name" value="<?php echo isset($_POST['name']) ? $_POST['name'] : ''; ?>" />

...but this is just messier.

Link to comment
Share on other sites

I have a form going right - using _POST method. Like so:
$name = $_POST['name'];

I want to retrieve that variable in another webpage to display their name. The code is in an External PHP File. If The 'Captcha' is wrong the email won't be sent and I would assume the information would still be held in the variables. What I want to do is Grab the content of these variables and redisplay them so they don't have to retype their data. How do I do this?

See I figured if it doesn't send it's still going to be in the $name variable right? So in turn I could use <?php echo _GET['name'] > and post it right? I mean if the form isn't on the page and I just want to post the variables.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...