-1
<select name="months" id="months" >
        <option value="0" >Select Months *</option>
        <option value="3000" >6 Months</option>
        <option value="6000" >12 Months</option>
        <option value="9000" >18 Months</option>
</select>



$message .= "<br>Selected Months : " . $_POST['months']; 

Need to $post text, not value of a dropdown selected element.

4

3 回答 3

2

You can not post the text. You can post the value only of any input type.

To post the text change the select box:

<select name="months" id="months" >
        <option value="0" >Select Months *</option>
        <option value="6 Months" >6 Months</option>
        <option value="12 Months" >12 Months</option>
        <option value="18 Months" >18 Months</option>
</select>

OR

If you want to post text and value then use a hidden field to store the text of selected item before submit the form put the text in that hidden field by JS or jQuery. and you will get the text by that hidden field.

于 2013-09-20T11:50:54.043 回答
1

You should change your value then:

<select name="months" id="months" >
        <option value="0" >Select Months *</option>
        <option value="6 Months" >6 Months</option>
        <option value="12 Months" >12 Months</option>
        <option value="18 Months" >18 Months</option>
</select>

After all, it is the VALUE that is posted.

于 2013-09-20T11:50:08.797 回答
0

You can do it in the following way:

array-config.php - a config file with select box options that can be included as required.

<?php
$select_box = array(
  '0' => 'Select Months *',
  '3000' => '6 Months',
  '6000' => '12 Months',
  '9000' => '18 Months',
);
?>

The HTML (PHP script)

<?php
include_once('array-config.php');
echo '<select name="months" id="months">';
foreach($select_box as $key => $val) {
   echo '<option value="' . $key . '">' . $val . '</option>';
}
echo '</select>';
?>

Form post retrieval script

<?php
include_once('array-config.php');
$message .= "<br>Selected Months : " . $select_box[$_POST['months']];
?>

Hope it helps.

于 2013-09-20T12:00:10.173 回答