Re: processing html forms and keeping the values
| From: | Kim Madsen | Date: | Wed, 25 Nov 2009 19:18:56 +0000 |
| Subject: | Re: processing html forms and keeping the values | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-300097@lists.php.net to get a copy of this message | ||
Merlin Morgenstern wrote on 2009-11-24 18:38:
This is not so easy. I am doing some checking with php on the values and if one failes php returns via GET to the form with the help of header location:
$parameter = "&demo=this";
HEADER("Location:/test.html?error=1".$parameter);
exit;
I would need to change way to many things in order to simply change to post.
Isn't there another way?
This is what I normally do with larger forms:
1. create the form as a function: form()
2. submit the form to the same page
3. test relevant input and if the fail print form()
Example:
function form() {
print '
<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<input type="text" name="email" value="'.$_POST['email'].'">
<input type="submit" name="submit" value="send form">
</form>';
}
if($_POST['submit']) {
// test email is entered
if(!$_POST['email']) {
print "error: you must enter an e-mail address";
form();
}
else {
// do stuff from here...} } else form(); With a 50 field form this is a nice approach for me :-) -- Kind regards Kim Emax - masterminds.dk