Re: Creating forms dynamically

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux