Currently I've been working on a form I've got it validating client side but I want server side also.
Now I'm not overly confident nor familiar with PHP, so I think i may have it set up correctly.
Here is the code:
<?php
// Check To See If Form Was Submitted Correctly
if(isset($_POST['submit'])) {
$valid = 1;
// Variables
$name = $_POST['name'];
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$topic = $_POST['topic'];
$budget = $_POST['budget'];
$description = $_POST['description'];
if ( $name == "Name..." || " " ) {
$valid = 0;
$error1 = '<img src="images/errorformicon.gif" alt="Error Form Icon" />';
}
if ( $email == "E-mail..." ) {
$valid = 0;
$error2 = '<img src="images/errorformicon.gif" alt="Error Form Icon" />';
}
else {
$valid = 1;
}
if ( $valid == 1 ) {
// The E-mail Message
$mailmsg = 'The following E-mail has been sent to you via your contact form:' . "\n\n";
$mailmsg.= 'Name: ' . $name . "\n\n";
$mailmsg.= 'Email: ' . $email . "\n\n";
$mailmsg.= 'Telephone: ' . $telephone . "\n\n";
$mailmsg.= 'Topic: ' . $topic . "\n\n";
$mailmsg.= 'Budget: ' . $budget . "\n\n";
$mailmsg.= 'Project Description: ' . $description . "\n\n";
}
// Sending the E-mail
if(mail('mail@domain.com',$topic,$mailmsg,"From: $email")) {
header("Location: thankyou.php");
}
}
?>
Now the email is formatting correctly however it doesn't appear to be checking if the form is valid before sending the email, it just sends it no matter the input.
Any ideas?
Thanks,
PS. Please ignore stuff like == "Name..." this will be changed, I'm just trying to get it working correctly first.
Edited by jm2008, 22 March 2008 - 08:11 AM.
