Forum
Add blank option to Product Options select menu
I want to be able to add a blank option element as the first option in the Product Options select menu so that the purchaser has to choose an option (without it they could leave the first option displayed which may not be what they want). Any advice how I can add this please?
I don't believe there's a widely supported HTML form element to do that.
Hi Drew, it is not an html element I am looking for, it is how to add one to the Product Options array in the shop without having to actually add a blank 'option'. It's OK, I will dig deeper and see how I can add into onto the beginning of the array of options returned from the db.
If anyone else is trying to do this, my work around was to add a blank space to the optionValues when the query is run by changing the sql in the function get_product_options (in / near line 127) in addons/apps/perch_shop_paypal/PerchShop_Product.class.php (please note that this will be applied to all option select menus so only use if that is what you want). I also had to add a parameter to be sent through from the shop to ensure the blank option isn't also added in the admin area.
Then in addons/apps/perch_shop_paypal/perchShop_Products.class.php I changed line 431 to send through 'true' as the parameter value to the function (above)
Finally I added in a required value for the select menu in the product_options.html template but this is only required if you need customers to select an option:
Is that not just the same as using the
allowempty
attribute?I don't know?
I thought allowempty was so that a select menu could be submitted without an option being selected but I needed to have a blank option at the start of the menu but still require that the person selects an option.
allowempty
will add an empty item, andplaceholder
can be used to set its label.Oh right - this was what I was asking about in my initial question :(
Ah ok. From the question is sounded like you were after a combo box.
All sorted now?
I know it is a month later but I have just remembered that I hadn't tired this out and it doesn't work as I expected so still need help.
I have a select menu using allowempty="true" as below:
There is no empty option at the start of the list as expected and the placeholder text doesn't display as suggested.
Are you running the latest version?
How do I find out which version I am running (I know I have updated a couple of months ago)?
Emma, to find the version of perch your running, and app for that matter...
Login to Perch, Click Settngs (top right) Then click Diagnostics Tab.
The info you seek is in the diagnostics report.
Often its best to copy and paste this info into your post to help the forum better troubleshoot your issue.
Thanks Robert, I was trying to find out in my developer account and in the site files - didn't even think about looking in the site's admin area.
OK, I have just done an update onto 2.7.4 and the allowempty still isn't working.
Emma, I have a fully up to date perch installation and I used the code you posted above...
screenshot
and the form is working exactly as you describe you need it.
I am thinking there is something goofy with your installation or maybe elsewhere in your form.
I know this is frustrating and I am trying to help you, but I think we are still going to need for you to post your entire diagnostics report because it contains bits of information which allow us to duplicate your installation or at least verify your using compatible apps.
Please post that and your entire form template.
Ummm, interesting. My complete form template:
The only apps I am using are:
Installed apps: content (2.7.4), assets (2.7.4), categories (2.7.4), perch_forms (1.7), perch_shop_paypal (1.2.1) App runtimes: <?php $apps_list = array( 'content', 'perch_forms', 'perch_shop_paypal' );
If anyone has a problem with this, I have found the solution. very time I make a change to a form template I have to go into my perch admin for the site and re-save the same form for the changes to take affect.