dawndmd Posted December 31, 2007 Share Posted December 31, 2007 Hi, I have created a form and implemented PHP. Everything works find except that for some reason the option menus are mandatory for someone to drop down. What do I add in my code to make the drop down optional? Here is some code below from my form. If you need to look at my form further you can at www.branicdesigns.com/tiny/products.php and view code. It is a very big form so I can't post the whole thing here. //Check drop down if (in_array($_POST['quantity13'], $options)) { $om = $_POST['quantity13']; } else { $errors[] = 'Please select a valid option from the drop down.'; } Quote Link to comment https://forums.phpfreaks.com/topic/83848-help-with-making-a-drop-down-menu-an-option/ Share on other sites More sharing options...
dawndmd Posted December 31, 2007 Author Share Posted December 31, 2007 I didn't know if this code would help for an answer as well as the quote in previous post. Thank you. $options = array("Quantity", "1", "2", "3"); // set up options array, may be easier ways depending on data. <SELECT NAME="quantity1"> <?php foreach ($options as $option) { echo "<option>$option</option>\n"; }?> </SELECT> Quote Link to comment https://forums.phpfreaks.com/topic/83848-help-with-making-a-drop-down-menu-an-option/#findComment-426742 Share on other sites More sharing options...
dawndmd Posted January 1, 2008 Author Share Posted January 1, 2008 Can anyone please help me with this? Thank you. Dawn Quote Link to comment https://forums.phpfreaks.com/topic/83848-help-with-making-a-drop-down-menu-an-option/#findComment-427370 Share on other sites More sharing options...
revraz Posted January 1, 2008 Share Posted January 1, 2008 Not sure what you mean by mandatory and optional. This line here will produce an error if no option is picked else { $errors[] = 'Please select a valid option from the drop down.'; Are you saying you don't want that? Quote Link to comment https://forums.phpfreaks.com/topic/83848-help-with-making-a-drop-down-menu-an-option/#findComment-427372 Share on other sites More sharing options...
Barand Posted January 1, 2008 Share Posted January 1, 2008 Include the default value (when no option is selected) in the $options array Quote Link to comment https://forums.phpfreaks.com/topic/83848-help-with-making-a-drop-down-menu-an-option/#findComment-427384 Share on other sites More sharing options...
anon Posted January 1, 2008 Share Posted January 1, 2008 So you don't want those menu's to drop down? Quote Link to comment https://forums.phpfreaks.com/topic/83848-help-with-making-a-drop-down-menu-an-option/#findComment-427388 Share on other sites More sharing options...
dawndmd Posted January 2, 2008 Author Share Posted January 2, 2008 Barand, I think what I need is a default value. What would that look like in the options array? What would happen if I simply took out the line that revraz stated Not sure what you mean by mandatory and optional. This line here will produce an error if no option is picked else { $errors[] = 'Please select a valid option from the drop down.'; Are you saying you don't want that? I want the menus to have the ability to drop down but not be mandatory for someone to have to use the drop down menu. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/83848-help-with-making-a-drop-down-menu-an-option/#findComment-427746 Share on other sites More sharing options...
teng84 Posted January 2, 2008 Share Posted January 2, 2008 and what is the problem now ? Quote Link to comment https://forums.phpfreaks.com/topic/83848-help-with-making-a-drop-down-menu-an-option/#findComment-427765 Share on other sites More sharing options...
Barand Posted January 2, 2008 Share Posted January 2, 2008 The options array used to build the dropdown in your second post conatins "Quantity". This would be the default if no quantity were selected. The validation array, I'm guessing, would jiust contain 1,2,3. However both my method and Revraz's have potential problems. If you permit "Quantity" as a valid value in $om, something down the line could fail when you come to use $om. With Revraz solution $om doesn't get set, so something down the line could fail when you come to use $om. Quote Link to comment https://forums.phpfreaks.com/topic/83848-help-with-making-a-drop-down-menu-an-option/#findComment-427963 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.