Jump to content


Photo

PHP/HTML Registration


  • Please log in to reply
5 replies to this topic

#1 simonsays

simonsays
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 26 August 2006 - 07:02 PM

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!

#2 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 26 August 2006 - 07:12 PM

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
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#3 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 26 August 2006 - 07:55 PM

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>

Ronald   8)
RTFM is an almost extinct art form, it should be subsidized.

#4 simonsays

simonsays
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 26 August 2006 - 09:37 PM

well, that 's a decent solution... but isn't browser supposed not to reset these values?

#5 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 26 August 2006 - 10:15 PM

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)
RTFM is an almost extinct art form, it should be subsidized.

#6 simonsays

simonsays
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 27 August 2006 - 12:01 PM

ok, thanks a lot :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users