Log in

View Full Version : Form Validation on Popup Without Reloading...



remp
08-21-2012, 01:05 AM
I have the following code:


<form name="contact" method="POST" action="<?php $PHP_SELF; ?>">
<table width="456" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="28" valign="top">Your name:</td>
<td><input name="name" type="text"></td>
</tr>

<tr>
<td height="28" valign="top">Subject:</td>
<td><input name="subject" type="text"></td>
</tr>
<tr>
<td height="28" valign="top">E-mail address:</td>
<td><input name="email" type="text"></td>
</tr>
<tr>
<td height="28" valign="top">Contact No:</td>
<td><input name="contact" type="text"></td>
</tr>
<tr>
<td height="28" valign="top">Message:</td>
<td><input name="message" type="text"/></td>
</tr>
<tr>
<td>&nbsp;</td>
<td valign="top" align="center">
<input type="submit" value="Submit" name="submit"></td>
</tr>
</table>
</form>

and the processing php code:


<?php
if(isset($_POST['submit'])) {
$to = $user->email; //put your email address on which you want to receive the information
$subject = $_POST['subject']; //set the subject of email.
$headers = "From:".$_POST['email'];
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$message = "<table><tr><td>Your Name</td><td>".$_POST['name']."</td></tr>
<tr><td>E-Mail</td><td>".$_POST['email']."</td></tr>
<tr><td>Contact No</td><td>".$_POST['contact']."</td></tr>
<tr><td>Message</td><td>".$_POST['message']."</td>
</tr></table>" ;
$sendemail = mail($to, $subject, $message, $headers);

if ($sendemail){
echo "Email Sent Correctly";
}
else {
echo "Email Not Sent";
}
}
?>

I have not been able to make it work with a modal popup without it closing the popup window and not validating the form. Does anybody know of a form that would allow me to make it work or help me adjust the code?

Thanks in advance.