simonsays Posted August 26, 2006 Share Posted August 26, 2006 I am looking for some help. I realized that I do not know how to do it. I have a registration form with several fields.When user submits data, there is a script that controls data (whether username exists or not, first and second password match, etc...)If there is an error, it adds it to an array and displays the text(s) of error(s) on the same page where form is.However, all the data input into form fields is missing then and the user has to go through registration again... How do I do, so the data is saved, so the user has to repair only invalid fields and does not have to fill all the fields all over again. Is there any trick? Maybe the problem is with Smarty template engine that I am using?Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/18741-phphtml-registration/ Share on other sites More sharing options...
AdRock Posted August 26, 2006 Share Posted August 26, 2006 I never thought of that before and i noticed my form doesn't do it. I don't know if it would work becuase i haven't tried it but i would save the field values in variables and echo the vriables in the form fields so if the there is no variable then it echos nothing but if it has something in it iit should echo itI have done something similar so the field values acho something from a database so i don't see why it wouldn't work Link to comment https://forums.phpfreaks.com/topic/18741-phphtml-registration/#findComment-80838 Share on other sites More sharing options...
ronverdonk Posted August 26, 2006 Share Posted August 26, 2006 [code]You have to re-display your form with the $_POSTed fields that you have. Like this:[code<?php$msg = array();if (isset($_POST['submitted'])) { if (!isset($_POST['field1']) ) { $msg[] = 'Enter a value in field1'; } if (isset($_POST['field1']) && $_POST['field1'] != 'Hello') { $msg[] = 'Field1 has invalid value'; } if (!isset($_POST['field2']) ) { $msg[] = 'Enter a value in field2'; } if (isset($_POST['field2']) && $_POST['field2'] != 'You too') { $msg[] = 'Field2 has invalid value'; } // validate the rest of your input if (!isset($msg)) { // you are okay, continue processing the values } else { print '<ul><li><b>'; print implode('</b></li><li><b>',$msg); print '</b></li></ul>'; }}?> <form name="xx" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input type="hidden" name="submitted" value="1" /> Enter field1 input <input type="text" name="field1" value="<?php echo (isset($_POST['field1'])) ? $_POST['field1'] : ""; ?>" /><br /> Enter field2 input <input type="text" name="field2" value="<?php echo (isset($_POST['field2'])) ? $_POST['field2'] : ""; ?>" /><br /> <input type="submit" value="Submit It!" /> </form> </html>[/code]Ronald 8) Link to comment https://forums.phpfreaks.com/topic/18741-phphtml-registration/#findComment-80843 Share on other sites More sharing options...
simonsays Posted August 26, 2006 Author Share Posted August 26, 2006 well, that 's a decent solution... but isn't browser supposed not to reset these values? Link to comment https://forums.phpfreaks.com/topic/18741-phphtml-registration/#findComment-80885 Share on other sites More sharing options...
ronverdonk Posted August 26, 2006 Share Posted August 26, 2006 You start a new script the second time, so all local variables are reset (or beginning anew). Since you enter your variables again via the form (you actually pass them with the POST action, you can pick them up via the $_POST. Ronald 8) Link to comment https://forums.phpfreaks.com/topic/18741-phphtml-registration/#findComment-80897 Share on other sites More sharing options...
simonsays Posted August 27, 2006 Author Share Posted August 27, 2006 ok, thanks a lot :) Link to comment https://forums.phpfreaks.com/topic/18741-phphtml-registration/#findComment-81073 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.