Totally Zenned
- Join Date:
- Jan 2007
- Location:
- Los Angeles, California, United States
- Posts:
- 10,011
- Plugin Contributions:
- 3
custom forms - data collection
Well I may have been confused by the array section of this code, but I understood enough of this post to figure out how to adapt the validation portion of this code for my own form's dropdowns..
// do you want to set a default selection? if not, use '0':
$default_pulldown_selection = '2';
//For validation, you're looking for the contents of the $_POST['my_pulldown_menu'] variable
// this is only set after "submit" is clicked.
$pulldown_selected_item = (isset($_POST['my_pulldown_menu'])) ? $_POST['my_pulldown_menu'] : $default_pulldown_selection ;
//build an array of entries to be displayed on the template:
$pulldown_contents[] = array('id'=>'0', 'text'=>'Please Select');
$pulldown_contents[] = array('id'=>'1', 'text'=>'Choice Number 1');
$pulldown_contents[] = array('id'=>'2', 'text'=>'Choice Number 2');
$pulldown_contents[] = array('id'=>'3', 'text'=>'Choice Number 3');
$pulldown_contents[] = array('id'=>'4', 'text'=>'Choice Number 4');
$pulldown_contents[] = array('id'=>'5', 'text'=>'Choice Number 5');
// you could add some validation here.
if ($pulldown_selected_item==0) {
$messageStack->add_session('header','Please select an option from the pulldown menu','error');
}
From this I added the following to my own form handler:
if ($question4==0) {
$error = true;
$messageStack->add('customer_questionnaire','Do you prefer virgin hair?: Please select an option from the pulldown menu');
}
if ($question5==0) {
$error = true;
$messageStack->add('customer_questionnaire','Have you had experience with premium hair?: Please select an option from the pulldown menu');
}
```I've seen the question on how to add dropdowns in this thread a bit.. So I wanted to share what I did in case it is of use to someone else.
Plus I also wanted to share the rest of the code posted [here](http://www.zen-cart.com/forum/showpost.php?p=212034&postcount=2) because someone with REAL coding skills might be able to use this information the way it's meant to be used.. :laugh: