Jump to content

Retaining Value in Registration


PRG_Jughead

Recommended Posts

there is the registration form, User inputs the value and submit the form. Processing of the user inputs is done in the next page and if the user inputs are not correct it redirects into registration form.

 

The Problem is that the registration form is displayed with error message But the previously inputted value are not there. The user input must be preserved.

 

How can i do it ??

Link to comment
https://forums.phpfreaks.com/topic/69153-retaining-value-in-registration/
Share on other sites

You need to have the form post back to the same page. Then use a switch to determine if data was posted. If data was posted attempt to verify data. If verification passes, process the data and then redirect to a confirmation page. If verification passes then show the form. The fields in the form shouls always show the values of the input fields by default. If it is the first load of the page, then those values would be blank.

 

<?php

if (isset($_POST['submit'])) {
  //Do the verification
  $errors = false;
  if (isempty($_POST['field1'])) {
    $errors = "Field 1 cannot be blank";
  }
}

if ($errors == false) {
  //Process the data then redirect to confirmation page
  //processing script
  header("Location: confirmation.php");
}

//Show the form
?>
<form name="test" method="POST">
Field 1: 
<input type="text" name="field1" value="<?php echo $_POST['field1']; ?>">
<button name="submit" type="submit">Submit</button>
</form>

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.