Re: Creating forms dynamically

From: Date: Wed, 15 Mar 2006 22:34:53 +0000
Subject: Re: Creating forms dynamically
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-231979@lists.php.net to get a copy of this message
On Tuesday 14 March 2006 20:21, Paul Goepfert wrote: > If anyone has any ideas on how to create the form when the error messages > are displayed without having to code it a second time please let me > know. I use an assoc. array that matches the form inputs, for example: $FormDisplayData = array( 'username' => '', 'email' => '', 'city' => '' ); and a flag variable that is set when an error is encountered. Then in the form: echo "Enter your username: <input type=\"text\" name=\"username\" value=\"{$FormDisplayData['name']}\">"; if ($FoundErrors) { echo "Invalid username!";} and so on. This way, first time through the form the array is empty and the error flag is false - user gets a form ready to be filled in. If you get a processing error, populate the $FormDisplayData array with the values from $_POST, and the user gets his input back to correct, and a message telling him why. Neat, huh? There are undoubtedly many other ways to do this, but this is the only one I know :) Hope this helps. Mark

« previous php.general (#231979) next »