Jump to content

Help with making a drop down menu an option


dawndmd

Recommended Posts

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.';

}

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.