Hi everyone, first of all, I'd like to wish everyone a very merry festive season and a happy new year for 2010 .... ;-)

I am working on a registration that is going fine at the moment,

when all fields are populated and the submit is pressed, the script checks for duplicated usernames, email addresses and mobile \ cell numbers and returns an error message notifying the user.

What I would like to learn is how to retain all the information already entered into the registration page.

ie. if a user completes 99% of the registration script, but forgets to upload \ select and profile image, The script rightly provides an error notifying the user that he \ she has not selected \ uploaded an image.

But the script also removes all data from the form.
Its annoying me and im only testing it, I'm sure it would annoy a user who wants to register.

How can I retain the form data

//Array to store validation errors
	$errmsg_arr = array();
	//Validation error flag
	$errflag = false;

this is how i am sending the error message

if($gender == 'Select') {
		$errmsg_arr[] = 'Please select male or female gender';
		$errflag = true;

The error is then shown on the reg form.php
I would like to retain all other information entered into the form.

Hoping someone can help with this

7 Years
Discussion Span
Last Post by LloydFarrell

Ajax could help here - have the submit button run a js then a server side check before sending the form.
Otherwise if your form handling code is in the same page as the form - repopulate the fields with data from the $_POST variables.
If the form handling code is in a different page (recommended), then you could use a variety of methods to repopulate the fields: $_SESSION or $_COOKIE variables. I'd use $_SESSION myself, but up to you. Once the form data has been repopulated, you need to kill the particular $_SESSION variables.


   ...(do form handling and validation - e.g. check for image)...
   if($form_error){ //if an error
       $_SESSION['regform']['username'] = stripslashes($_POST['username']);
       ...(etc - all fields)...

   $username = $_SESSION['regform']['username']; 

<form method="post" action="formhandler.php" ...>
   <label for="username">Username:</label>
   <input type="text" id="username" name="username" value="<?php echo $username;?>" />
   <input type="submit" id="regformsubmit" name="regformsubmit" value="Register" />

Edited by diafol: n/a


Hi Ardav many thanks for your reply,

im pretty new to php and web-design,

the form_reg.php calls form_vallidation.php and returns any errors found back to form_reg at the top of the form.

I will have a go at your solution and reply back. Iv not yet coded with js, but i am keen to learn new technologies,

Many thanks

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.