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
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>

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.