<p>I am populating a drop-down with product variants like this:</p>

<pre><code>&lt;select name="mySelect" class="form-control"&gt;
&lt;option value=""&gt;Select&lt;/option&gt;
{% for purchasable in product.variants %}
    &lt;option {% if purchasable.stock &lt;= 0 and purchasable.unlimitedStock == false %}disabled {% endif %}
        value="{{ purchasable.purchasableId }}"&gt;
            {{ purchasable.myProduct.label }} &amp;ndash; {{ purchasable.price|currency(cart.currency) }}
    &lt;/option&gt;
{% endfor %}
&lt;/select&gt;
</code></pre>

<p>This is not going to be a required field, so its possible a user could submit without making a choice.</p>

<p>The error I currently get is:</p>

<pre><code>Not a purchasable ID
</code></pre>

<p>Which makes complete sense since I am not passing anything to the cart.</p>

<p>Is it best to have a product called "Select" and just have it be zero dollars? Or is there a way - maybe custom plugin - that will skip the input if it has no value?</p>

<p><strong>EDIT</strong></p>

<p>Or do I force the user to make a choice of "No thanks" (or whatever is applicable) then that option has a price of zero dollars...</p>

<p><strong>EDIT 2</strong></p>

<p>If the user does not make a choice, then Craft gets really angry because I have not passed in a valid purchasable ID (a <code>null</code> value).</p>

<p>In the screenshot, the profile is optional. The user doesn't <em>have</em> to pick one. If they do, all is well since they have chosen a valid purchasable. The selected default value is <code>null</code>.</p>

<p><a href="https://i.sstatic.net/K69jV.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/K69jV.png" alt="enter image description here"></a></p>

<p><strong>EDIT 3</strong></p>

<p>Well, I guess for now I take everything back. I've tried several times to break it but I can't today. I haven't changed anything that I can think of, but this seems to be working. If I don't choose anything, I am taken to the <code>/cart</code> page as expected.</p>

<pre><code>&lt;option value=""&gt;Select Profile&lt;/option&gt;
    {% for profile in profiles %}
        &lt;option value="{{ profile.defaultVariant.purchasableId }}" data-price="{{ profile.defaultVariant.price|currency(cart.currency) }}"&gt;
            {{ profile.title }} &amp;ndash; {% if profile.defaultVariant.price == 0 %} Included with registration {% else %} {{ profile.defaultVariant.price|currency(cart.currency) }}{% endif %}
        &lt;/option&gt;
    {% endfor %}
</code></pre>

CC BY-SA 3.0
2016-02-04T23:00:46.203Z
Have you tried `value="null"` on the empty option?
Josh Angell
CC BY-SA 3.0
2016-02-05T16:57:41.597Z
Hi Josh - no luck. Still get a 500 error.
Damon
CC BY-SA 3.0
2016-02-05T17:12:35.917Z
Perhaps try `false` instead. Shooting in the dark here but it's worth a try! Maybe ask in the commerce channel on Slack as well?
Josh Angell
CC BY-SA 3.0
2016-02-05T17:38:17.000Z
Absolutely - I appreciate the suggestions!
Damon
CC BY-SA 3.0
2016-12-13T12:30:57.717Z
"This is not going to be a required field, so its possible a user could submit without making a choice." - How can a user submit the form without a purchasable ID? What does the form do if not adding a product to the cart? (which will require a purchasable ID)
Luke Pearce
CC BY-SA 3.0
2016-12-13T14:23:42.453Z
Hi Luke - I've updated my question with a screen shot to help show what I currently have.
Damon
CC BY-SA 3.0
2016-12-13T18:48:08.393Z
So from your 3rd edit it looks like you found a solution?
Brad Bell
CC BY-SA 3.0
2016-12-13T19:08:06.487Z
So far so good - can't say I really found anything. :)
I'll vote to close.
Damon
<plugin-craftcommerce>
How can I pass a null value to commerce?
# How can I pass a null value to commerce?

(Asked by: username_0 on 2016-02-04)

I am populating a drop-down with product variants like this:

Select
{% for purchasable in product.variants %}
    
            {{ purchasable.myProduct.label }} – {{ purchasable.price|currency(cart.currency) }}
    
{% endfor %}


This is not going to be a required field, so its possible a user could submit without making a choice.
The error I currently get is:
Not a purchasable ID

Which makes complete sense since I am not passing anything to the cart.
Is it best to have a product called "Select" and just have it be zero dollars? Or is there a way - maybe custom plugin - that will skip the input if it has no value?
EDIT
Or do I force the user to make a choice of "No thanks" (or whatever is applicable) then that option has a price of zero dollars...
EDIT 2
If the user does not make a choice, then Craft gets really angry because I have not passed in a valid purchasable ID (a null value).
In the screenshot, the profile is optional. The user doesn't have to pick one. If they do, all is well since they have chosen a valid purchasable. The selected default value is null.

EDIT 3
Well, I guess for now I take everything back. I've tried several times to break it but I can't today. I haven't changed anything that I can think of, but this seems to be working. If I don't choose anything, I am taken to the /cart page as expected.
Select Profile
    {% for profile in profiles %}
        
            {{ profile.title }} – {% if profile.defaultVariant.price == 0 %} Included with registration {% else %} {{ profile.defaultVariant.price|currency(cart.currency) }}{% endif %}
        
    {% endfor %}

**Tags:** plugin-craftcommerce

> **Comments:**
> **username_1**: Have you tried `value="null"` on the empty option?  
> **username_0**: Hi Josh - no luck. Still get a 500 error.  
> **username_1**: Perhaps try `false` instead. Shooting in the dark here but it's worth a try! Maybe ask in the commerce channel on Slack as well?  
> **username_0**: Absolutely - I appreciate the suggestions!  
> **username_2**: "This is not going to be a required field, so its possible a user could submit without making a choice." - How can a user submit the form without a purchasable ID? What does the form do if not adding a product to the cart? (which will require a purchasable ID)  
> **username_0**: Hi Luke - I've updated my question with a screen shot to help show what I currently have.  
> **username_3**: So from your 3rd edit it looks like you found a solution?  
> **username_0**: So far so good - can't say I really found anything. :) I'll vote to close.  

---

## 0 answers

