Jump to content

PHP Form Validation


brad_langdon

Recommended Posts

Hi,

 

When a user submits my form it then goes to "sendmail.php" where it is then checked to see if any of the required fields were left empty etc. So far so good.

 

If a required field has been left blank then I use a header to redirect the user back to the form page while defining a variable as true so that a message will pop p telling them to fill in all required fields etc.

 

My question is this...when I redirect to the form page all of the fields are blank again...how do I redirect while keeping the text that the user has typed out in the form so that they don't have to start from scratch again?

 

Any help would be very appreciated...I have searched for a solution but have had no luck so far.

 

:confused:

Link to comment
https://forums.phpfreaks.com/topic/168047-php-form-validation/
Share on other sites

You can have some checks when creating your form. See if the session variables are set and if they are you echo the values from them in the form fields. Sample line which will echo $_SESSION['name'] in to the text field if the session variable exists (now it does as it should do after error and redirect).

 

<?php
$_SESSION['name'] = 'Bob';
// inside your form...
echo '<input type="text" name="name" value="'. $name = isset($_SESSION['name']) ? $_SESSION['name'] : ''.'" />';
?>

 

Edit: don't forgot to start your session with session_start() in the beginning of every file that you want to use these variables.

Link to comment
https://forums.phpfreaks.com/topic/168047-php-form-validation/#findComment-886335
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.