GGMcGee
June 6th, 2008, 12:53 AM
Hi,
I've set up a contact form for a website I'm making.
The pages involved is contact.html which is the page the HTML form is on, and mailer.php which contains the PHP script that sends an email.
The form works fine, but I really want to add in a script of sorts that sets every input box (Name, Email and Enquiry in this case) as a required field, and doesn't send the email unless each field has something type in it.
I've tried a couple of Javascript scripts I found online, but they are not working...
Can anyone give me a 100% guaranteed working script? I don't care if it's Javascript or PHP, whatever works.
Thanks a lot for your help.
<form method="post" action="mailer.php">
<p> </p>
<table width="298" border="0" align="center" cellpadding="0" cellspacing="5">
<tr>
<td width="56" align="right" valign="top"><span class="style1">Name</span></td>
<td width="267" align="left" valign="top"><input name="name" type="text" id="name" size="30" /></td>
</tr>
<tr>
<td align="right" valign="top"><span class="style1">Email</span></td>
<td align="left" valign="top"><input name="email" type="text" id="email" size="30" /></td>
</tr>
<tr>
<td align="right" valign="top"><span class="style1">Enquiry </span></td>
<td align="left" valign="top"><span class="style1">
<textarea name="enquiry" cols="30" rows="9" id="enquiry"></textarea>
</span></td>
</tr>
<tr>
<td align="right" valign="top"><span class="style1"></span></td>
<td align="left" valign="top"><span class="style1">
<input name="submit" type="submit" id="submit" value="Send" />
</span></td>
</tr>
</table>
</form>
<?php
if(isset($_POST['submit'])) {
$to = "thisemail@somewebsitethatthisemailisgoingto.com";
$subject = "Website - Enquiry";
$name = $_POST['name'];
$email = $_POST['email'];
$enquiry = $_POST['enquiry'];
$body = "Name: $name\n
Email: $email\n
Enquiry: $enquiry\n
";
echo "Your enquiry has been submitted to Some Website That This Email Is Going To!";
mail($to, $subject, $body);
} else {
echo "An error has occured. Please try again later.";
}
?>
I've set up a contact form for a website I'm making.
The pages involved is contact.html which is the page the HTML form is on, and mailer.php which contains the PHP script that sends an email.
The form works fine, but I really want to add in a script of sorts that sets every input box (Name, Email and Enquiry in this case) as a required field, and doesn't send the email unless each field has something type in it.
I've tried a couple of Javascript scripts I found online, but they are not working...
Can anyone give me a 100% guaranteed working script? I don't care if it's Javascript or PHP, whatever works.
Thanks a lot for your help.
<form method="post" action="mailer.php">
<p> </p>
<table width="298" border="0" align="center" cellpadding="0" cellspacing="5">
<tr>
<td width="56" align="right" valign="top"><span class="style1">Name</span></td>
<td width="267" align="left" valign="top"><input name="name" type="text" id="name" size="30" /></td>
</tr>
<tr>
<td align="right" valign="top"><span class="style1">Email</span></td>
<td align="left" valign="top"><input name="email" type="text" id="email" size="30" /></td>
</tr>
<tr>
<td align="right" valign="top"><span class="style1">Enquiry </span></td>
<td align="left" valign="top"><span class="style1">
<textarea name="enquiry" cols="30" rows="9" id="enquiry"></textarea>
</span></td>
</tr>
<tr>
<td align="right" valign="top"><span class="style1"></span></td>
<td align="left" valign="top"><span class="style1">
<input name="submit" type="submit" id="submit" value="Send" />
</span></td>
</tr>
</table>
</form>
<?php
if(isset($_POST['submit'])) {
$to = "thisemail@somewebsitethatthisemailisgoingto.com";
$subject = "Website - Enquiry";
$name = $_POST['name'];
$email = $_POST['email'];
$enquiry = $_POST['enquiry'];
$body = "Name: $name\n
Email: $email\n
Enquiry: $enquiry\n
";
echo "Your enquiry has been submitted to Some Website That This Email Is Going To!";
mail($to, $subject, $body);
} else {
echo "An error has occured. Please try again later.";
}
?>