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>
Problem Dereferencing
With these types and tables:
Not capturing all the information we require in the form.......
Hi Guys,I was wondering if you would share some more of your knowledge today, I'm hoping it will be quite a simple answer for you but one that is boggling us here! ;-)We have an html form that users
I think i'm using the syntax incorrectly
Hi Everyone!I'm new to this forum and a newbie with PHP - I'm glad I found this site - I hope to learn a lot! For my first and hopefully one of few questions, lol..I told my boss i'd help him out
Target costs on Process orders not calculating
Hi All,
MySQL query problem
When I try to run the following piece of code, I get this error:QuoteWarning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/muskelmann098/public_html/build.php on line
calendar dates and hours compare problem
i have a calendar in wordpress, everything works great except that i can make 2 meetings at the same date, time and room without receiving any error i don't know where to start to compare the days
Beginner question regarding Array's
Hi everyone, the page im working on has an array of variable at the top...Code: $define_list = array('PRODUCT_LIST_MODEL' => PRODUCT_LIST_MODEL, 'PRODUCT_LIST_NAME'
How to kill asynchronous postback / current postback?
Hi,here is my problem:I have a web site with many pages of which some may take time to process results. If a user wants to go to another page (by clicking on the top menu) the browser locks up till
Passing variables with pagination - iterating through unique id per link
Hi everyone,I have seen a few topics like this one. Still cant find the specific thing, so I am asking - does anyone know this?I am trying to combine a mysql query with this code I found at
Passing Variables
What I'm wanting to do is when the user clicks on Arenas it will know the name of the country it's wanting to see the list of Arenas for but don't know how to pass it. I'm sure it's with a hidden