Jump to content

PHP/HTML Registration


simonsays

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.