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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.