Forum

Thread tagged as: Question, Configuration, PayPal

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?

Emma Davis

Emma Davis 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

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.

public function get_product_options($is_shop = false) {
        if ($is_shop) {
            $sql = 'SELECT optionID, optionKey, CONCAT(" ,", optionValues) as optionValues FROM '. PERCH_DB_PREFIX.'shop_product_options WHERE productID = '.$this->id();
        } else {
            $sql = 'SELECT optionID, optionKey, optionValues FROM '. PERCH_DB_PREFIX.'shop_product_options WHERE productID = '.$this->id();
        }


        return $this->db->get_rows($sql);

    }

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)

$product_opts = $posts[$i]->get_product_options(true);

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:

<perch:input type="select" required="true" id="<perch:shop id="optionKey" />" name="os<perch:shop id="perch_item_index" />" options="<perch:shop id="optionValues" />" />
Drew McLellan

Drew McLellan 2638 points
Perch Support

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.

Drew McLellan

Drew McLellan 2638 points
Perch Support

allowempty will add an empty item, and placeholder can be used to set its label.

Oh right - this was what I was asking about in my initial question :(

Drew McLellan

Drew McLellan 2638 points
Perch Support

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:

<perch:input id="enquirysubject" type="select" label="Enquiry Topic" options="Show Hire, Agility Equipment, Pre Agility Training, Agility Training Classes, Puppy Training &amp; Obedience Classes, Private Training, General" allowempty="true" placeholder="Please select ..." required="true" />

There is no empty option at the start of the list as expected and the placeholder text doesn't display as suggested.

Drew McLellan

Drew McLellan 2638 points
Perch Support

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:

<perch:form id="contact-form" method="post" app="perch_forms" role="form">
    <perch:label for="name">Your name</perch:label>
        <perch:input id="name" type="text" required="true" label="Name"/>
    <perch:label for="email">Your email</perch:label>
        <perch:input id="email" type="email" required="true" label="Email"/>
    <perch:label for="enquirysubject">What is your enquiry related to?</perch:label>
        <perch:input id="enquirysubject" type="select" label="Enquiry Topic" options="Show Hire, Agility Equipment, Pre Agility Training, Agility Training Classes, Puppy Training &amp; Obedience Classes, Private Training, General" allowempty="true" placeholder="Please select ..." required="true" />
    <perch:label for="enquiry">Your enquiry</perch:label>
        <perch:input id="enquiry" type="textarea" required="true" label="Enquiry"/>
    <perch:input type="submit" id="submit" class="button radius" value="Send Enquiry">

    <perch:success>
        <perch:content id="success" type="textarea" label="Thank you message" html="true" editor="ckeditor"/>
    </perch:success>
</perch:form>

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.