session causing my field to clear! need help!

elo! i’m back and i need help. :D

i have a registration form that receives user’s input like firstname,lastname…etc. and of course a validation.
the problem is when a user mistakenly inputs a wrong validation and tries to submit it the error message and the fields are cleared, and i think it’s wrong it should still display the user’s input.

here is my code for the registration:
[php]

<? /* Include Files *********************/ require_once 'library/config.php'; //include"login.php"; /*************************************/ require_once 'include/header.php'; $errorMessage = ''; $secret = md5(uniqid(mt_rand(), true)); $_SESSION['secret'] = $secret; $message = (isset($_GET['error']) && $_GET['error'] != '') ? $_GET['error'] : ''; ?>
<?php require_once 'include/top.php';?>
<?php require_once 'include/mainmenu.php';?>
<?php echo $message; ?>
Notice: except for the secondary address, all fields are required to be filled up. Before clicking register you must make sure that you have checked the checkbox. thank you
User Account Registration
</tr>
<tr>
	<td>First Name:</td>
	<td><input type="text" id='firstname' name="FirstName"/></td>
</tr>
<tr>
	<td>Last Name:</td>
	<td><input type="text" id='lastname' name="LastName"/></td>
</tr>
     <tr>
<td colspan="2" align="center">
<input type="checkbox" id='terms' name="terms"/>I Agree to the terms and conditions of IECC online<br />
	<input name="btnAddUser" type="submit" value="Register" onClick="return checkPassword();" />
	
	<input type=button value="Cancel" onClick="self.location='index.php'">
	
</td>

Personal Information

[/code]

and here is the succes page:

[code]

<?php if (!isset($_POST['secret'])) if (($_SESSION['secret'] != $_POST['secret']) || (!isset($_SESSION['secret']))) { //Call error handling function with $problem = 2 (minor security breach) } else { //unset() session variable //unset($_SESSION['secret']); } require_once 'processreg.php'; ?>

Thank you for registering at IECComputers online. You may now use your IECC account for online orders


Click here to Log-in
[/php]

**MOD Edit - Added php tags for better readability.
*Note: PHP Tags in script are correct BBCode incorrectly displays them.

that has to be done manually.

maybe this topic helps:
http://phphelp.com/forums/viewtopic.php?t=7474

P.S.: use the tag for checkboxes

<input type="checkbox" id='terms' name="terms"/><label for="terms">I Agree to the terms and conditions of IECC online</label>that makes the text clickable as well

what do you mean by manually?? is my codes really un-arranged? is it hard to understand? i’m really sorry because i’m still a college student and this is my undergrad project :smiley:

no prob, i try to explain it.

when the form is submitted it’s submitted to a “new” page. (even if it is the same php-file). the client can’t know that it’s still the same page, as php may return a lot of diffrent pages with the same php file.
this means, what u been told is simply wrong.

that means u have to keep track of that. by preseting inputs with the value-atribute to contain the already enterd information.
thats what i ment with manualy: there is no automatism doing that for u.

ur code is ok, but none of this (keeping the values) is done yet.

this has to be done in the folowing way:

<input name="nameofthefield" value="<?php echo $_POST['nameofthefield'] ?>" />

but to make it tolaly right it would be:

<input name="nameofthefield"<?php if(isset($_POST['nameofthefield']))echo ' value="'.htmlentities($_POST['nameofthefield']).'"' ?> />

there are some exaples and what to do in cast of radio-buttons, checkboxes, textareas, and selects disscussed here http://phphelp.com/forums/viewtopic.php?t=7474

i don’t wanna write all of that again, plz read it. but if u have problems understanding something in there or aditional questions feel fre to just ask again.

sir it’s been solved at last! i put sessions on every textboxes and post a

$_SESSION[‘FName’] = $FirstName;

on the function under:

$FirstName = $_POST[‘FirstName’];

and it delivers the result i wanted… thanks for the help sir! :D

Sponsor our Newsletter | Privacy Policy | Terms of Service