php - Place holder for form dropdown select type? -


how add "please select option" default shown option in drop down select box in form.

i'm modifying magento module adding in new input fiends on frontend saves table in magento's database. form works correctly saving information database shows 1st item array used list options. if user doent change option, array [0] added database. want add place holder wont added database, prompt user select option.

this information called:

$fields[] = array(         'name'     => 'vehicle_make',         'label'    => mage::helper('sublogin')->__('make'),         'required' => true,         'type'     => 'select',         'style'    => 'width:100px',         'cssclass' => '',         'options'  => array ("acura", "alfa romeo","audi", "bmw", "buickm", "cadillac", "chevrolet", "chrysler", "dodge", "fiat", "ford", "gmc", "honda", "hyundai", "infiniti", "jaguar", "jeep", "kia", "land rover", "lexus", "lincoln", "maserati", "mazda", "mercedes-benz", "mini", "mitsubishi", "nissan", "porsche", "ram", "scion", "smart", "subaru", "suzuki", "toyota", "volkswagen", "volvo", "yamaha"),     ); 

this used show input field:

if ($formfield['type'] == 'select' || $formfield['type'] == 'multiselect')                     {                         $selectedoptions = $sublogin->getdata($formfield['name']);                         $selectedoptions = explode(',', $selectedoptions);                         ?>                         <select                              <?php echo ($formfield['type'] == 'multiselect')?"multiple=multiple":""; ?>                              id="<?php echo $formfield['name'] ?>"                              name="<?php echo ($formfield['type'] == 'multiselect')? $formfield['name'].'[]':$formfield['name'] ?>">                         <?php foreach ($formfield['options'] $optionvalue => $optionlabel) {                             $selected = '';                             if (in_array($optionvalue, $selectedoptions))                                 $selected = 'selected';                                                           echo '<option '.$selected.' value="'.$optionvalue.'">'.$optionlabel.'</option>';                         } ?>                         </select> 

vehicle make

in above code

<select                              <?php echo ($formfield['type'] == 'multiselect')?"multiple=multiple":""; ?>                              id="<?php echo $formfield['name'] ?>"                              name="<?php echo ($formfield['type'] == 'multiselect')? $formfield['name'].'[]':$formfield['name'] ?>">                         <?php foreach ($formfield['options'] $optionvalue => $optionlabel) {                             $selected = '';                             if (in_array($optionvalue, $selectedoptions))                                 $selected = 'selected';                                                           echo '<option '.$selected.' value="'.$optionvalue.'">'.$optionlabel.'</option>';                         } ?>                         </select> 

add default option before foreach this

<select                              <?php echo ($formfield['type'] == 'multiselect')?"multiple=multiple":""; ?>                              id="<?php echo $formfield['name'] ?>"                              name="<?php echo ($formfield['type'] == 'multiselect')? $formfield['name'].'[]':$formfield['name'] ?>"> //added line of code                             <option name="please-select" value="100">please select option</option>                         <?php foreach ($formfield['options'] $optionvalue => $optionlabel) {                             $selected = '';                             if (in_array($optionvalue, $selectedoptions))                                 $selected = 'selected';                                                           echo '<option '.$selected.' value="'.$optionvalue.'">'.$optionlabel.'</option>';                         } ?>                         </select> 

you can use value , name this. use can use javascript validate it.

hope helps.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -