Dear Everyone,
I have been struggling with how to make my comments box required. Here is my HTML and PHP code. I believe the problem is textarea versus textfield, since a comments textfield does work - I need a textarea, though. I’ve been researching this a lot, so any help you can give me would be greatly appreciated! I’m including the entire form in PHP, as I am no longer sure which part holds the answer.
Thank you!!
Chava
HTML
<textarea name="comments" cols="26" rows="5" style="background-color:#fff;"></textarea>
[php]
<?php if(isset($_POST['email'])) { $email_to = "[email protected]"; $email_subject = "Contact Form"; function died($error) { echo "Sorry, we found errors in your form submission.
";
echo $error."
";
echo "Please fix these errors here, so I can properly respond to your submission.
";
die();
}
// validation expected data exists
if(!isset($_POST['fname']) ||
!isset($_POST['lname']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) &&
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form your submitted.');
}
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email_from = $_POST['email'];
$telephone = $_POST['telephone'];
$comments = $_POST['comments'];
$error_message = "";
$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
if(!eregi($email_exp,$email_from)) {
$error_message .= 'The e-mail address is either blank or in the wrong format.
';
}
$string_exp = "^[a-z .'-]+$";
if(!eregi($string_exp,$fname)) {
$error_message .= 'The first name is either blank or includes invalid characters.
';
}
/*$string_exp = "^[a-z .'-]+$";
if(!eregi($string_exp,$lname)) {
$error_message .= 'The name you entered does not appear to be valid.
';
}*/
$string_exp = "^[a-z .'-]";
if(!eregi($string_exp,$comments)) {
$error_message .= 'The comments box is blank.
';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "fname".clean_string($fname)."\n";
$email_message .= "lname".clean_string($lname)."\n";
$email_message .= "email".clean_string($email_from)."\n";
$email_message .= "telephone".clean_string($telephone)."\n";
$email_message .= "comments".clean_string($comments)."\n";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<?
}
?>
[/php]