/    Sign up×
Community /Pin to ProfileBookmark

POST – send diffrent details depending on selection

Hi, I am very new to php and have no idea where to start with this, i have googled it but i wasn’t really to sure what to put in.

I have an email form on my site using the “post” method. Its for my work, and the form is an on-line booking form. On the page there is a select box where they select if they have hired before . Is it possible so that if they have, the email only sends some of the data, as if they have hired before they only have to fill out there name email and dob. this is my php to send the form

[code]<?php
if(isset($_POST[’email’])) {

// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = “[email protected]”;
$email_subject = “Your email subject line”;
$thankyou = “thanks.html”; // thank you page

function died($error) {
// your error code can go here
echo “We are very sorry, but there were error(s) found with the form you submitted. “;
echo “These errors appear below.<br /><br />”;
echo $error.”<br /><br />”;
echo “Please go back and fix these errors.<br /><br />”;
die();
}

// validation expected data exists
if(!isset($_POST[‘colect2’]) ||
!isset($_POST[‘coltime2’]) ||
!isset($_POST[’email’]) ||
!isset($_POST[‘retur2’]) ||
!isset($_POST[‘rettime2’])) {
died(‘We are sorry, but there appears to be a problem with the form you submitted.’);
}

$colect = $_POST[‘colect2’]; // required
$ctime = $_POST[‘coltime2’]; // required
$email_from = $_POST[’email’]; // required
$return = $_POST[‘retur2’]; // not required
$rtime = $_POST[‘rettime2’]; // required
$car = $_POST[‘cartype’]; // required
$days = $_POST[‘days2’]; // required
$price = $_POST[‘price2’]; // required
$name = $_POST[‘name’]; // required
$dd = $_POST[‘date’]; // required
$dm = $_POST[‘month’]; // required
$dy = $_POST[‘year’]; // required
$from = $_POST[‘from’]; // required
$job = $_POST[‘job’]; // required
$tyr = $_POST[‘tyr’]; // required
$liheld = $_POST[‘liheld’]; // required
$lipart = $_POST[‘2part’]; // required
$homeadd = $_POST[‘homeadd’]; // required
$tempadd = $_POST[‘tempadd’]; // required
$workadd = $_POST[‘workadd’]; // required
$phone1 = $_POST[‘phone1’]; // required
$phone2 = $_POST[‘phone2’]; // required
$claim = $_POST[‘claim’]; // required
$drmo = $_POST[‘drmo’]; // required
$befor = $_POST[‘hbfo’];

$error_message = “”;
$email_exp = ‘/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}$/’;
if(!preg_match($email_exp,$email_from)) {
$error_message .= ‘The Email Address you entered does not appear to be valid.<br />’;
}

if(strlen($rtime) < 2) {
$error_message .= ‘The Comments you entered do not appear to be valid.<br />’;
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = “Form details below.nn”;

function clean_string($string) {
$bad = array(“content-type”,”bcc:”,”to:”,”cc:”,”href”);
return str_replace($bad,””,$string);
}

$email_message .= “Hired In last 5 Years: “.clean_string($befor).”nn”;

$email_message .= “Collect on: “.clean_string($colect).”nn”;

$email_message .= “At: “.clean_string($ctime).”nn”;

$email_message .= “Return on: “.clean_string($return).”nn”;

$email_message .= “At: “.clean_string($rtime).”nn”;

$email_message .= “Car Type: “.clean_string($car).”nn”;

$email_message .= “Days: “.clean_string($days).”nn”;

$email_message .= “Price Quoted:: “.clean_string($price).”nn”;

$email_message .= “Email: “.clean_string($email_from).”nn”;

$email_message .= “Name: “.clean_string($name).”nn”;

$email_message .= “Day: “.clean_string($dd).”nn”;

$email_message .= “Month: “.clean_string($dm).”nn”;

$email_message .= “Year: “.clean_string($dy).”nn”;

$email_message .= “Country of origin: “.clean_string($from).”nn”;

$email_message .= “Occupation: “.clean_string($job).”nn”;

$email_message .= “Year Test Passed: “.clean_string($tyr).”nn”;

$email_message .= “Country driving licence issued in : “.clean_string($liheld).”nn”;

$email_message .= “Counterpart:: “.clean_string($lipart).”nn”;

$email_message .= “Home address: “.clean_string($homeadd).”nn”;

$email_message .= “If not UK resident please give temporary address: “.clean_string($tempadd).”nn”;

$email_message .= “Employers name/address: “.clean_string($workadd).”nn”;

$email_message .= “Home Phone: “.clean_string($phone1).”nn”;

$email_message .= “Mobile Phone : “.clean_string($phone2).”nn”;

$email_message .= “Accidents/Claims: “.clean_string($claim).”nn”;

$email_message .= “Driven in 12 months: “.clean_string($drmo).”nn”;

// create email headers
$headers = ‘From: ‘.$email_from.”rn”.
‘Reply-To: ‘.$email_from.”rn” .
‘X-Mailer: PHP/’ . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>

<!– include your own success html here –>

<script>location.replace(‘<?php echo $thankyou;?>’)</script>

<?php
}
?>[/code]

As you can see it messages all the data there, but if $befor = $_POST[‘hbfo’]; = yes then i only want the email to send

[code]$colect = $_POST[‘colect2’]; // required
$ctime = $_POST[‘coltime2′]; // required
$email_from = $_POST[’email’]; // required
$return = $_POST[‘retur2’]; // not required
$rtime = $_POST[‘rettime2’]; // required
$car = $_POST[‘cartype’]; // required
$days = $_POST[‘days2’]; // required
$price = $_POST[‘price2’]; // required
$name = $_POST[‘name’]; // required
$dd = $_POST[‘date’]; // required
$dm = $_POST[‘month’]; // required
$dy = $_POST[‘year’]; // required
$from = $_POST[‘from’]; // required[/code]

thanks in advanced

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NoEffinWayFeb 21.2012 — Something like:
[code=php]if (isset($_POST['checkbox']) && $_POST['checkbox'] != 'somevalue'){
$email_message .= "Car Type: ".clean_string($car)."nn";

$email_message .= "Days: ".clean_string($days)."nn";

$email_message .= "Price Quoted:: ".clean_string($price)."nn";

$email_message .= "Email: ".clean_string($email_from)."nn";


}[/code]

You are going to probably want some JS to hide unneeded forms.
×

Success!

Help @chrisboots spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...