Jump to content

Archived

This topic is now archived and is closed to further replies.

simonsays

PHP/HTML Registration

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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 it

I have done something similar so the field values acho something from a database so i don't see why it wouldn't work

Share this post


Link to post
Share on other sites
[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&nbsp;&nbsp;
<input type="text" name="field1" value="<?php echo (isset($_POST['field1'])) ? $_POST['field1'] : ""; ?>" /><br />
        Enter field2 input&nbsp;&nbsp;
<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)

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites

×

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.