Re: form submission error trapping

From: Date: Sun, 17 Feb 2002 23:52:19 +0000
Subject: Re: form submission error trapping
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-85133@lists.php.net to get a copy of this message
I guess the real challenge is converting a pre-existing page like the one I've described into one that can re-populate itself on an error condition. Building it that way from scratch is merely a programming task.
That's true, however there are a few ways to cheat :). For example, in my form I have a State and Country popup menu. Rather than trying to write code that selects the proper one to match the post data, I simply create a new entry at the top:
      <select name="state">
        <?
         	 if(isset($state)) {
         	  	$statename = GetStateName($state);
         	  	echo "<option selected value='$state'>$statename";
         	 }
        ?>
        <option value="">Select a state
        <option value=AL>Alabama
This works because I've already verified the data. If the data doesn't pass verification, it would be reset and would fail the isset($state) test. Otherwise, most form elements are pretty easy to assign values to. Steven J. Walker Walker Effects www.walkereffects.com steve@walkereffects.com On Sunday, February 17, 2002, at 03:42 PM, Ken wrote:
-----Original Message----- From: Steven Walker [mailto:steve@walkereffects.com] I created one php page that both displays the form and validates the input. When the user hits the submit button, it submits the data to itself. If anything is missing from the page, the form is reshown with missing fields highlighted and the other fields filled in. If on the other hand the info passes the validation test, the information is shown to screen a new button (hidden form) allows the user to continue.
Only catch is, you have to build all that logic to populate your fields. Piece of cake when you have a simple form, not so easy when you have a dynamically-generated form (with a variable number of inputs) including multi-select buttons and the like. I guess the real challenge is converting a pre-existing page like the one I've described into one that can re-populate itself on an error condition. Building it that way from scratch is merely a programming task. - Ken kenzo@free-music.com


« previous php.general (#85133) next »