<p>A parameter with no value set returns an empty string <code>''</code> for <code>craft.request.getParam()</code>. But if the whole parameter is not included at all, it returns <code>null</code>.</p>

<p>This means you can test for <code>null</code> (→ <a href="http://twig.sensiolabs.org/doc/tests/null.html" rel="noreferrer">see Twig docs</a>) like so:</p>

<pre><code>{% if craft.request.getParam('myparam') is not null %}
    My Parameter is included in the query string!
{% endif %}
</code></pre>

CC BY-SA 3.0
2015-08-05T09:54:23.780Z
2015-08-05T09:54:23.780Z
carlcs
<p>You can use the <code>defaultValue</code> to determine if the value is there or not. </p>

<pre><code>{% if craft.request.getParam('myVar', -1) != -1 %}
  myVar is here!
{% else %}
  myVar is missing...
{% endif %}
</code></pre>

CC BY-SA 3.0
2015-08-05T06:51:13.143Z
2015-08-05T06:51:13.143Z
fuling
<p>Is it possible to determine whether or not a query string has a param with no value. For example</p>

<pre><code>http://www.test.com?myparam
</code></pre>

<p>Technically that's a valid url but the craft.request object doesn't appear to have a way to see that. craft.request.getParam('myparam') returns nothing as does craft.request.getQuery('myparam'). I have tried using an explicit test for 'true' and 'false' but no luck.</p>

<p>Right now I'm grabbing the entire query string value and then using the 'in' to find the param name but thats pretty fragile is another param or value contains the same string.</p>

<url><request><querystring>
Get query string param that has no value
# Get query string param that has no value

(Asked by: username_0 on 2015-08-04)

Is it possible to determine whether or not a query string has a param with no value. For example
http://www.test.com?myparam

Technically that's a valid url but the craft.request object doesn't appear to have a way to see that. craft.request.getParam('myparam') returns nothing as does craft.request.getQuery('myparam'). I have tried using an explicit test for 'true' and 'false' but no luck.
Right now I'm grabbing the entire query string value and then using the 'in' to find the param name but thats pretty fragile is another param or value contains the same string.

**Tags:** url, request, querystring


---

## 2 answers

### Answer by username_1 on 2015-08-05. Score: 5

A parameter with no value set returns an empty string '' for craft.request.getParam(). But if the whole parameter is not included at all, it returns null.
This means you can test for null (→ see Twig docs) like so:
{% if craft.request.getParam('myparam') is not null %}
    My Parameter is included in the query string!
{% endif %}


---

### Answer by username_2 on 2015-08-05. Score: 1

You can use the defaultValue to determine if the value is there or not. 
{% if craft.request.getParam('myVar', -1) != -1 %}
  myVar is here!
{% else %}
  myVar is missing...
{% endif %}


---

