Contact Form Not Working When I Add Validation Codes


Posted on 16th Feb 2014 07:03 pm by admin

So I built my first working PHP "Contact Us" like form. But, I have been trying to now make the form Validate for empty fields when the user hits the submit button. Problem is when I added in the code and tried to mesh the two together it doesn't work. First I had errors and fixed those, but now I just get a blank white screen and an email doesn't send.

I will admit that this is my first time working with PHP and I don't have a full understanding yet. Needless to say, I can't seem to figure it out and just need some help.

Code: [Select]<?php
if ( $_POST['submit'] ) {
$error = '';
if ( $_POST['name'] == '' ) {
$error = 'Error: Please enter your name';
}
if ( $_POST['phonenumber'] == '' ) {
$error = 'Error: Please enter your phone number';
}
if ( $_POST['appointmentdate'] == '' ) {
$error = 'Error: Please enter a date';
}
if ( $_POST['appointmenttime'] == '' ) {
$error = 'Error: Please enter an appointment time';
}
if ( $_POST['appointmenttype'] == '' ) {
$error = 'Error: Please enter an appointment type';
}
if ( !$error ) {
$to = "bizsumpark182@gmail.com";
$subject = "Someone Has Requested An Appointment!";
$name_field = $_POST['name'];
$phonenumber_field = $_POST['phonenumber'];
$appointmentdate_field = $_POST['appointmentdate'];
$appointmenttime_field = $_POST['appointmenttime'];
$appointmenttype_field = $_POST['appointmenttype'];

$body = "From: $name_fieldn Phone Number: $phonenumber_fieldn Requested Appointment Date:n $appointmentdate_fieldn Requested Appointment Time:n $appointmenttime_fieldn Requested Appointment Type:n $appointmenttype_field";

if (mail($to, $subject, $body)) {
header("location: http://www.mathewballard.com/devriesdental/thankyou.html");

} else {

echo "Sorry, there was an error processing your request.";
}
}
}
?>
Code for Form:

Code: [Select]<div id="content2" align="left">
<?php if ( $error ) { ?>
<p class="error"><?=$error;?></p>
<?php } ?>
<form method="post" action="appointment.php" name="apptform">
<label for="name"><b>Name</b></label><br />
<input type="text" name="name" size="20" value="<?=$_POST['name'];?>" /><br /><br />
<label for="phonenumber"><b>Phone Number</b></label> (Starting with areacode)<br />
<input type="text" name="phonenumber" size="20" value="<?=$_POST['phonenumber'];?>" /><br /><br />
<label for="apptdate"><b>Appointment Date</b></label><br />
<input type="text" name="appointmentdate" size="20" value="<?=$_POST['appointmentdate'];?>" /><br /><br />
<label for="appttime"><b>Appointment Time</b></label><br />
<input type="text" name="appointmenttime" size="20" value="<?=$_POST['appointmenttime'];?>" /><br /><br />
<label for="appttype"><b>Apointment Type</b></label> (i.e. Annual Checkup, drilling, etc.)<br />
<textarea rows="10" name="appointmenttype" cols="30" ><?=$_POST['appointmenttype'];?></textarea><br /><br />
<input type="submit" value="submit" name="submit" /><br />
</form>
</div>

217 Like 18 Dislike
Previous php-forum Next php-forum
Other php-forum

storing video files into mysql in php
hi

i have my video files in my folder ,
i have to store the path of the videos into db an

my two tables
table1 : col1 = topicid , col2 = topic

table2 : col1 = sentid, col2 = sentence

Cod

Gaining access to Drop Down Menu Variable
code is below, I am creating a drop down menu. I want to echo the value selected in the drop down me

echo $rows help
Hi all,

Hopefully something simple that I don't know!

I have this:

Code: [Selec

Passing vars to the DB
I have 3 small testing tables:

ID TYPE
1 pepperoni
2 C. bacon
3 taco

ID TY

Java API in PHP?
I have an application that we use internally here at the office.

The software company provide

Can anyone give me some link on .htaccess tutorial
i wish to have friendly url using .htaccess, but no idea yet about this

Hope that anyone cou

Alternate messaging
I have 4 strings in MySQL db1

$string1 : Hello
$string2 : Hi
$string3 : Great
$strin

Including calander to page - will not show other months than current??
im trying to add an existaing calander onto a profile page by using Code: <?php include "

Basic Question Regarding PHP Includes
Hi

Just starting out with PHP.

Working on a site that uses some basic includes, these

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash