Form handling question???
Posted: Wed Apr 19, 2006 10:38 am
What is the best way to make a field in a form required?
I have tried but I can't get it to work properly.
I have tried but I can't get it to work properly.
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
if(empty($_POST['requiredField'])){
// They didn't fill it in.
die('Sorry, you must fill in all fields');
} else {
// it was filled in
// continue processing form
}Code: Select all
<?
ini_set("SMTP","mail19.webcontrolcenter.com");
ini_set("smtp_port","8889");
ini_set("sendmail_from","InfoPack@postcardmania.com");
ini_set ('display_errors', 1);
error_reporting(E_ALL & ~E_NOTICE);
// order.php
//error_reporting(0);
// Check if form was submitted properly.
if ( isset($_POST['submit'])){
$problem = FALSE; // no problems so far
// CHECK FOR EACH VALUE
if (empty ($_POST['email'])) {
$problem = TRUE;
print ('<p><b>Please enter your email address.</b></p>');
}
if (!$problem){ //if there aren't ant problems
@mail("x@xxx.com", "Form Submission", $text, "From: Website");
$url = "http://www.xxxx.com/reportdownloaddent.asp";
Header("Location: $url");
} else { // forgot a field
print ('<p>Please go back and try again.</p>');
}
} // End of handle form IF
$text =
" Form Submission.
Details:
Date: " . date('D d M Y - h:i a') ."
Email: ". $_POST['email'] ."
Company Name: ". $_POST['companyname'] ."
Industry: ". $_POST['industry'] ."
First Name: ". $_POST['contactfirstname'] ."
Last Name: ". $_POST['contactlastname'] ."
Address: ". $_POST['address'] ."
City, St, Zip: ". $_POST['city'] ." ". $_POST['state'] ." ". $_POST['zip'] ."
Phone: ". $_POST['phone'] ."
Fax: ". $_POST['fax'] ."
How Referred:
Marketing Code: ". $_POST['marketing_code'] ."
Referred By: ". $_POST['referred_by'] ."
Search Engine: ". $_POST['search_engine'] ."
Magazine: ". $_POST['magazine'] ."
Currently use Direct Mail: ". $_POST['mail'] ."
If so this often: ". $_POST['howoften'] ."
Other types of marketing used: ". $_POST['types'] ."
Contact me: ". $_POST['contactme'] ."
";
?>