• I am trying to create a quotation form. This will be email to myself and the person who has filled in the form. I want to echo the selected value (I currently have this working) & assign a integer value to the selection. I then want to add the integers up to give a total. In my example below I have just included one selection but I will have quite a few of them in the form. Any help would be great!

    <label>What time would you like to 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 a time.';
        }
        $drop_off_time = $_POST['drop_off_time'];
    
        $emailTo = '[email protected]';
    	$subject = 'Fees Form Submission from '.$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: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
    
        mail($emailTo, $subject, $body, $headers);

    This all works fine. My problem is that I want to assign an integer to the selection. I’ve done this using a switch but it keeps printing out the selected value not the new value I have assigned. The code for this is 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 the total
    $total = $drop_off_time_price;

    This is what the email looks like

    Name: Frank
    Email: [email protected]
    Comments: I get the selected value but no the total….
    Drop Off Time: 8:00am
    Total: £0

Viewing 1 replies (of 1 total)
  • Thread Starter Northern Badger

    (@bassmanstu)

    The problem was with my switch. It isnt checking against the selection. Here is how I fixed it.

    1. Removed case; 0 – It needed a : not ; after case and it was already being checked
    2. Made the switch check drop_off_price
    $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;
    	}

    Hope this helps anyone else who gets stuck with a similar issue.

Viewing 1 replies (of 1 total)
  • The topic ‘Quotation Form – Echo two values from a PHP form selection’ is closed to new replies.