Re: still some problems with contact form
| From: | Mark Rees | Date: | Thu, 21 Jul 2005 11:19:04 +0000 |
| Subject: | Re: still some problems with contact form | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-219104@lists.php.net to get a copy of this message | ||
>Hello Mark
>An alternative (and more user-friendly) approach is to have the form's
>action as itself (i.e. the form on contact.php submits to contact.php). You
>can then identify which fields are incomplete and highlight them in the
>form. This will make it easier for users to see what they have done wrong
>and make the necessary corrections.
>in regards to this response on my contact form issues, how would I do
>these which you mention.
>currentlly the form is:
><form method="post" action="Thankyou.php"
>class="info_request">
>and the Thankyou.php code consit of what I posted on the forum.
>thanks for all of your help!!
A sample set up is as follows, with much room for improvement and
refinement, but it should give you the basic idea.
contact.php
<?php
#check that the form has been posted
$email=isset($_POST['email'])?$_POST['email']:'';
$emailerror=false;
if($email!=''){
#basic validation passed, so redirect
header("Location: Thankyou.php");
}else{
$emailerror=true;
}?>
email<br>
<form method="post" action="contact.php" class="info_request">
<input type="text" name="email" value="<?=$email;?>"
<?
if($_POST){
#show the input with a red background if the form has been posted and
if($emailerror==true)print 'style="background-color:red;"';
}
?>>
<input type="submit" value="submit">
</form>