Web Design Forum  
 
Go Back   Web Design Forum > Web Software > Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 12-16-2011, 03:32 AM   #1
New Member
 
Kdogg556's Avatar
 
Join Date: Dec 2011
Posts: 1
Default Add Required Fields to PHP contact form

Im doing a Contact form for a client and my php is limited. I need to make everything in this required. Here is the code:

<?php
ob_start();
if(empty($_POST)) {
$status = '';
$display_form = true;
} else {
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$pname = $_POST['pname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$prescrip = $_POST['prescrip'];
$payment = $_POST['payment'];
$card = $_POST['card'];
$shipping = $_POST['shipping'];
$error_list = array();

if(empty($fname)) {
$error_list[] = 'You did not supply your first name';
}
if(empty($lname)) {
$error_list[] = 'You did not supply your last name';
}
if(empty($pname)) {
$error_list[] = 'You did not supply your patient name';
}
if(empty($email)) {
$error_list[] = 'You did not supply your email address';
}
if(empty($phone)) {
$error_list[] = 'You did not supply a phone number';
}
if(empty($prescrip)) {
$error_list[] = 'You did not supply a prescription number';
}
if(empty($payment)) {
$error_list[] = 'You did not supply a payment method';
}
if(empty($shipping)) {
$error_list[] = 'You did not select a shipping method';
}
if(empty($error_list)) {

$email_contents = "The following message was sent to you from your website:\n";
$email_contents .= "First Name: $fname\n";
$email_contents .= "Last Name: $lname\n";
$email_contents .= "Patient Name: $pname\n";
$email_contents .= "Email: $email\n";
$email_contents .= "Phone Number: $phone\n";
$email_contents .= "Prescription Number: $prescrip\n";
$email_contents .= "Payment Type: $payment\n";
$email_contents .= "Payment Card On File: $card\n";
$email_contents .= "Shipping Method: $shipping\n";


$extra_headers = "From: $fname <$email>\n";
$extra_headers .= "Reply-To: $email";


mail('scripts@sbhmed.com','Refill Form Submission', $email_contents, $extra_headers );
header('Location: http://www.sbhmed.com/refill_request_confirm.php');
$status = "Thank you $fname. We will be sure to get back to you as soon as possible!";
$display_form = false;
} else {
$status = '<ul>';

foreach($error_list as $error_message) {
$status .= "<li>$error_message</li>";
}
$status .= '</ul>';

$display_form = true;
}
}

ob_flush();
?>

Thanks for your help
Kdogg556 is offline   Reply With Quote


Old 12-16-2011, 08:12 PM   #2
New Member
 
Join Date: Dec 2011
Posts: 3
Default

Check out

http://dynamicdrive.com/dynamicindex...uiredcheck.htm

for making fields mandatory.
rybussell is offline   Reply With Quote
Reply

Tags
contact form, php, required field

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 10:48 AM.


Camera Forum - Computer Forum - Web Design Forum

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.