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

Reply via email to