I am trying to code some IF statements into PHP that warns if certain fields are not populated on my contact form (http://bigdogcattle.com/?a=Cattle_Contact). Here is the code I have so far, but it will send me an email even if nothing is populated:
<?php if (isset($_POST['name'])){
$header = 'From: ' .$_POST['email'] .'\r\nContent-type: text/plain; charset=iso-8859-1\r\n';
$body = 'Name:: '. $_POST['name'];
$body .= '\nEmail:: '. $_POST['email'];
$body .= '\nPhone:: '. $_POST['phone'];
$body .= '\nMessage:: '. $_POST['message'];
$body = wordwrap($body,70);
$send = mail('info@bigdogcattle.com', 'Form submitted from your website', $body, $header);
if($send){
echo '<h3>Your messages was successfully sent....</h3>';
}else{
echo '<h3>There was a problem sending this message....</h3>';
}
}?>
Thanks
Jamie
Http://bigdogcattle.com
Contact form with required fields
Moderator: General Moderators
-
bigdogcattle
- Forum Newbie
- Posts: 1
- Joined: Fri Feb 26, 2010 5:58 pm
Re: Contact form with required fields
post the first lines of your form definition...
<form .....>
<form .....>
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Contact form with required fields
You would have something similar to :
Code: Select all
<?php
if ($_POST['namefield'] == '') {
//display error message
}
else {
//send the email if all required fields
//have filled.
} ?>“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: Contact form with required fields
If the visitor posts an empty name, then $_POST['name'] is set. With an empty string.bigdogcattle wrote:if (isset($_POST['name']))