Monday, 15 August 2011

html - Quotation Form - Echo two values from a PHP form selection -



html - Quotation Form - Echo two values from a PHP form selection -

i trying create quotation form. email myself , person has filled in form. want echo selected value (i have working) & assign integer value selection. want add together integers give total. in illustration below have included 1 selection have quite few of them in form. help great!

<label>what time start? <select required name="drop_off_time" id="drop_off_time-select" value="<?php if(isset($_post['drop_off_time'])) echo $_post['drop_off_time'];?>"> <option value="0"></option> <option value="8:00am">8:00am</option> <option value="8:30am">8:30am</option> <option value="9:00am">9:00am</option> </select> </label> if(isset($_request['drop_off_time']) && $_request['drop_off_time'] == '0') { echo 'please select time.'; } $drop_off_time = $_post['drop_off_time']; $emailto = 'me@gmail.com'; $subject = 'fees form submission '.$name; $sendcopy = trim($_post['sendcopy']); $body = "name: $name \n\nemail: $email \n\ncomments: $comments \n\ndrop off time: $drop_off_time \n\ntotal: £$total"; $headers = 'from: site <'.$emailto.'>' . "\r\n" . 'reply-to: ' . $email; mail($emailto, $subject, $body, $headers);

this works fine. problem want assign integer selection. i've done using switch keeps printing out selected value not new value have assigned. code below.

$drop_off_time_price = 0; switch ($drop_off_time_price) { case 0; echo 0; break; case "8:00am": echo 100; break; case "8:30am": echo 10000; break; case "9:00am": echo 100000; break; } //getting total $total = $drop_off_time_price;

this email looks like

name: frank

email: me@mail.com

comments: selected value no total....

drop off time: 8:00am

total: £0

you have few problems in logic:

you should checking against $drop_off_time in switch statements. should be:

switch ($drop_off_time) {

as @floatingrock has mentioned, case 0; should be:

case 0:

instead of echo 0 should assign value $drop_off_time_price

$drop_off_time_price = 0;

so total illustration should like:

$drop_off_time_price = 0; switch ($drop_off_time) { case "8:00am": $drop_off_time_price = 100; break; case "8:30am": $drop_off_time_price = 10000; break; case "9:00am": $drop_off_time_price = 100000; break; }

note: can remove check 0 in illustration since setting default value 0 0 price.

php html forms

No comments:

Post a Comment