Hi there I am currently completing a uni assignment using php and I thought it was finished until the lecturer dropped a bombshell and added another requirement. I have a contact us page which was basically just a shell (dead) page, he nows tell us that we have to do error validating on the form input with appropriate error messages, as well as echoing to the screen a message acknowledging receipt of the message when it is submitted. I am just not sure how to implement this. I am basically working with 3 files as well as the formatting files and the css, there is the contact.php, which is the basic web page, it calls in the other two files which are the includes/enquiryform.php and the includes/enquiryCheck.php. The page and the form work perfectly, but the error checking doesn't seem to do anything at all.
I will post all the code below hoping that someone can help me out of this very frustrating jam as this assignment is due on sunday and I have been working at this one final problem for 21 hours straight now and can't even think coherently any more. Oh some stuff id commented out, I have just been trying anything to try and make it work.
Also if anyone is genuinely interested in helping me out I will give you the url of where the site can be located, I am just not keen on revealing that on a public forum as it is a uni assignment and I don't want anyone copying it right now.
Cheers and sorry for rambling on I am just so very tired.
Giddyupgirl
contact.php
<?php
//session_start();
// relevant variables for the header
$page_title = "School Friends Club - Contact Us";
$page_meta_description = "School Friends Club contact us";
$page_meta_revised = "******* - 16/08/2009";
$page_name = "pageContact";
require ('includes/checkEnquiry.php');
//checkEnquiry();
require ('includes/navigation.php');
?>
<!-- Content Div -->
<div id="content">
<p><img src="images/contact title.jpg" alt="Contact Us" width="720" height="60" />
<img src="images/fancy67.gif" alt="bar" width="720" height="6" /></p>
<!-- Contact Div - Left-side Pane -->
<div id="contact">
<h3> The School Friends Club</h3>
<p> Lourdes College, Traralgon Campus<br />
Building 12A, Level 2, Room 7<br />
345 - 399 Grey Street <br />
PO Box 783 <br />
Traralgon VIC 3844 Australia <br />
Phone: +61 7 4651 5555<br />
Fax: +61 7 4651 7777<br />
Email: <a href="mailto:admin@sfc.com.au">admin@sfc.com.au</a></p>
</div> <!-- close contact div-->
<!-- Enquiry Div - Right-side Pane -->
<?php
require ('includes/enquiryform.php');
?>
</div> <!-- close content div-->
<?php
require ('includes/footer.php');
?>
</div> <!-- close page div -->
</div> <!-- close container div -->
</body>
</html>
includes/enquiryCheck.php
<?php
// variable for any errors
$errors;
/*function checkEnquiry()*/
{
// if a user has just clicked submit, these will be set
if (isset($_POST["submit"]))
{
// create variables to hold the data$name = $_POST['name'] ;
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$question = $_POST['question'] ;
// if the all fields contain data
if (!empty($name)&& !empty($email)&& !empty($question))
{
// Make sure the name contains only letters
if (ereg('[^a-zA-Z]+', $name))
{
$errors .= '<h3>Name can only contain letters.</h3>';
}
if (ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email))
{
$errors .= '<h3> Not a valid email address </h3>';
}
// Make sure the question contains only alphanumeric and numbers
if (ereg('[^A-Za-z0-9]+', $question))
{
$errors .= '<p>Your question can only contain letters and numbers.</p>';
}
}
else
{
// if the name is empty, create error
if (empty($name))
{
$errors .= '<p>Name field cannot be empty.</p>';
}
// if the email is empty, create error
if (empty($email))
{
$errors .= '<p>Email field cannot be empty.</p>';
}
// if the question is empty, create error
if (empty($question))
{
$errors .= '<p>Question field cannot be empty.</p>';
}
/*// if errors were created, print them to the screen
if(empty($errors))
{
echo '<h3>Your email was sent successfully</h3>';
}*/
}
}
}
?>
includes/enquiryform.php
<div id="enquiry">
<form action="mailto:admin@******.net" method="post">
<fieldset class="enquiryForm">
<legend class="legendHeader">Enquiry Form</legend>
<br />
<label for="name">Name:</label>
<input type="text" id="name"></input><br />
<label for="email">Email:</label>
<input type="text" id="email" ></input><br />
<label for="question">Question:</label>
<textarea rows="3" cols="20" id="question"></textarea>
<br /><br />
<input type="submit" value="Submit"></input>
<input type="reset" value="Reset"></input>
</fieldset>
</form>
</div> <!-- close enquiry div-->