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.
Form handling question???
Moderator: General Moderators
You'll want to check if the value sent is empty (or isset if its a checkbox or radio button), then do whatever based on the outcome of that
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
}Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
This is what i tried but it either gives me a blank page or completes the redirect
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'] ."
";
?>- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Form handling question???
Hello abrusky,
Take a look here and tell me if this is what you are trying to do.
http://zfutura.free.fr/fillform/inscriptfive.php
Regards.
Zythan
Take a look here and tell me if this is what you are trying to do.
http://zfutura.free.fr/fillform/inscriptfive.php
Regards.
Zythan