bladechob Posted September 26, 2006 Share Posted September 26, 2006 I need to get a submit form to 'remember the registration details so that if a visitor is filling in a form and misses a required field or puts in a malformed e-mail address that when they return to the form it has retained their earlier inputted stuff i.e. they don't have to go through the process of re-entering stuff all over again.Thanks :-* Quote Link to comment https://forums.phpfreaks.com/topic/22103-im-being-really-dim-here-but-can-someone-advise-the-code-for-form-memory/ Share on other sites More sharing options...
trq Posted September 26, 2006 Share Posted September 26, 2006 When the form is first submitted to store any inputed data into the $_SESSION array. Quote Link to comment https://forums.phpfreaks.com/topic/22103-im-being-really-dim-here-but-can-someone-advise-the-code-for-form-memory/#findComment-98912 Share on other sites More sharing options...
steveclondon Posted September 26, 2006 Share Posted September 26, 2006 if you mean for form validation then what you need to do is start the forms with values that are null and ERROR=FALSE. then after a form is submitted run through it and check for errors then return ie ERROR=TRUE if there is an error. Here you will get the values from your post information and then set the values in the form as these. Quote Link to comment https://forums.phpfreaks.com/topic/22103-im-being-really-dim-here-but-can-someone-advise-the-code-for-form-memory/#findComment-98917 Share on other sites More sharing options...
KevinM1 Posted September 26, 2006 Share Posted September 26, 2006 My first post -- yay! :)It sounds like you want a sticky form, a kind of form that will alert the user that they did something wrong (like not filling in a form element) upon submission, without bringing them to an error page. I made a simple one in my own attempts at learning PHP that seems to work well. Of course, you'll need to modify it for your specific purpose, but it's simple enough to modify easily. I recommend using regular expressions in the test statements, though. I was using JavaScript to do it as a test exercise, but that's not a secure method of validation. The files I include in my code (header.inc and footer.inc) are just basic XHTML. They only contain the header info (like page title, any CSS, that sort of thing) and the closing tags for the footer (</body> and </html>). Hope this helps![code]<?php$page_title = 'Sticky Form Test';include('header.inc');$message = NULL;if(isset($_POST['submit'])){ if(empty($_POST['username'])){ $u = FALSE; $message .= "Please input your username!<br />"; } else { $u = $_POST['username']; } if(empty($_POST['password'])){ $p = FALSE; $message .= "Please input your password!<br />"; } else { $p = $_POST['password']; } if(empty($_POST['email'])){ $e = FALSE; $message .= "Please input your e-mail address!"; } else { $e = $_POST['email']; } if($u && $p && $e){ echo "You correctly submitted everything!"; }}?><form id="inputform" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <fieldset class="narrow"><legend>Please input your information</legend> <p><label for="username">Name:</label><input name="username" id="username" type="text" class="txt" value="<?php if(isset($_POST['username'])) echo $_POST['username']; ?>" /></p> <p><label for="password">Password:</label><input name="password" id="password" type="password" class="txt" /></p> <p><label for="email">E-mail Address:</label><input name="email" id="email" type="text" class="txt" value="<?php if(isset($_POST['email'])) echo $_POST['email']; ?>"/></p> <p><input type="submit" name="submit" id="submit" value="Submit" /></p> </fieldset></form><?phpif(isset($message)){ echo "<div style='color: #FF0000;'>$message</div>";}include('footer.inc');?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/22103-im-being-really-dim-here-but-can-someone-advise-the-code-for-form-memory/#findComment-98983 Share on other sites More sharing options...
bladechob Posted September 27, 2006 Author Share Posted September 27, 2006 Thanks, that'll do nicely - congrats on your first post matey Quote Link to comment https://forums.phpfreaks.com/topic/22103-im-being-really-dim-here-but-can-someone-advise-the-code-for-form-memory/#findComment-99568 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.