Answers.Body: <p>This error could happen if the <code>p</code> param is set to <em>something</em>, but the value doesn’t actually contain a hyphen.</p>
  
  <p>If you want to find out what the problematic value is, enable <a href="http://buildwithcraft.com/help/dev-mode" rel="nofollow">Dev Mode</a> and then check your browser console > <strong><code>Application Log</code></strong> > <strong><code>GET Info</code></strong> or <strong><code>POST Info</code></strong> (depending on the request type).</p>
  
  <p>To make your code more bulletproof you can replace this line:</p>
  
  <pre><code>{% set price = price ? price|split('-') %}
  </code></pre>
  
  <p>with:</p>
  
  <pre><code>{% set price = (price and price matches '/-/') ? price|split('-') %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-20T17:08:20.997Z
Answers.Text: Thanks, that was indeed the problem. The price param is being set to 'search' in the GET array when no value is given. How does that happen?
Answers.UserDisplayName: Jonathan Melville
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-20T17:11:16.013Z
Answers.Text: That would depend on your actual form. Can you post the rendered form HTML?
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-20T17:17:16.057Z
Answers.Text: My search form is here. The price param has the name 'p', which is getting set to 'search' if no option is selected.
   https://gist.github.com/jonathanmelville/3f6d57b20ad0ec9220c1
Answers.UserDisplayName: Jonathan Melville
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-20T17:22:58.127Z
Answers.Text: Is there any JavaScript code being executed on this form? Nothing in that HTML would result in a `p=search` param. And Craft isn’t doing anything that would manipulate the params like that either.
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-20T17:23:58.363Z
Answers.Text: There's no JavaScript doing anything with this form. So strange...
Answers.UserDisplayName: Jonathan Melville
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-20T17:25:49.793Z
Answers.Text: Sorry, just realized what the problem is. `p` is the GET parameter that your .htaccess redirect is assigning the URI path to. You’ll have to choose a different name for that param (both in the search form and the results page), since it’s conflicting with that.
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-20T17:00:47.013Z
Answers.LastActivityDate: 2015-02-20T17:00:47.013Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>I have an advanced search that searches real estate properties by the usual criteria: price range, Bedrooms, Bathrooms... In the form, the default is "Any" if they don't care about a particular option.</p>
  
  <p>On the results page, I'm checking for a null value in case an option wasn't selected. Despite this, I'm still getting the message 'Key "1" for array with keys "0" does not exist' if the price option is missing. What is causing this?</p>
  
  <p>My search results page looks like this:</p>
  
  <pre><code>{% set price = craft.request.getParam('p') %}
  {% set price = price ? price|split('-') %}
  
  {% set br = craft.request.getParam('br') %}
  {% set br = br ? br %}
  
  {% set ba = craft.request.getParam('ba') %}
  {% set ba = ba ? ba %}
  
  
  &lt;h1&gt;Search Results&lt;/h1&gt;
  
  {% set searchResults = craft.entries({
      section: 'properties',
      propertyPrice: price ? ['and', '&gt;= ' ~ price[0],'&lt;= ' ~ price[1]],
      bedrooms: br ? [ 'and', '&gt;= ' ~ br ],
      bathrooms: ba ? [ 'and', '&gt;= ' ~ ba ],
      order: 'score'
  }) %}
  
  {% if searchResults|length %}
  
  &lt;ul&gt;
      {% for entry in searchResults %}
      &lt;li&gt;{{ entry.title }}: {{ entry.propertyPrice|currency('USD', true) }}: BR: {{ entry.bedrooms }}, BA: {{ entry.bathrooms }}&lt;/li&gt;
      {% endfor %}
  &lt;/ul&gt;
  
  {% else %}
  &lt;h1&gt;No Results Found&lt;/h1&gt;
  {% endif %}
  </code></pre>
  
Tags: <search>
Title: Advanced search returning 'Key "1" for array with keys "0" does not exist'
ThreadText: # Advanced search returning 'Key "1" for array with keys "0" does not exist'
  
  (Asked by: username_0 on 2015-02-20)
  
  I have an advanced search that searches real estate properties by the usual criteria: price range, Bedrooms, Bathrooms... In the form, the default is "Any" if they don't care about a particular option.
  
  On the results page, I'm checking for a null value in case an option wasn't selected. Despite this, I'm still getting the message 'Key "1" for array with keys "0" does not exist' if the price option is missing. What is causing this?
  
  My search results page looks like this:
  
  ```
  {% set price = craft.request.getParam('p') %}
  {% set price = price ? price|split('-') %}
  
  {% set br = craft.request.getParam('br') %}
  {% set br = br ? br %}
  
  {% set ba = craft.request.getParam('ba') %}
  {% set ba = ba ? ba %}
  
  <h1>Search Results</h1>
  
  {% set searchResults = craft.entries({
      section: 'properties',
      propertyPrice: price ? ['and', '>= ' ~ price[0],'<= ' ~ price[1]],
      bedrooms: br ? [ 'and', '>= ' ~ br ],
      bathrooms: ba ? [ 'and', '>= ' ~ ba ],
      order: 'score'
  }) %}
  
  {% if searchResults|length %}
  
  <ul>
      {% for entry in searchResults %}
      <li>{{ entry.title }}: {{ entry.propertyPrice|currency('USD', true) }}: BR: {{ entry.bedrooms }}, BA: {{ entry.bathrooms }}</li>
      {% endfor %}
  </ul>
  
  {% else %}
  <h1>No Results Found</h1>
  {% endif %}
  
  ```
  
  **Tags:** search
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-02-20. Score: 2 | Accepted answer
  
  This error could happen if the `p` param is set to *something*, but the value doesn’t actually contain a hyphen.
  
  If you want to find out what the problematic value is, enable [Dev Mode](http://buildwithcraft.com/help/dev-mode) and then check your browser console > **`Application Log`** > **`GET Info`** or **`POST Info`** (depending on the request type).
  
  To make your code more bulletproof you can replace this line:
  
  ```
  {% set price = price ? price|split('-') %}
  
  ```
  
  with:
  
  ```
  {% set price = (price and price matches '/-/') ? price|split('-') %}
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks, that was indeed the problem. The price param is being set to 'search' in the GET array when no value is given. How does that happen?  
  > **username_1**: That would depend on your actual form. Can you post the rendered form HTML?  
  > **username_0**: My search form is here. The price param has the name 'p', which is getting set to 'search' if no option is selected.  https://gist.github.com/username_0/3f6d57b20ad0ec9220c1  
  > **username_1**: Is there any JavaScript code being executed on this form? Nothing in that HTML would result in a `p=search` param. And Craft isn’t doing anything that would manipulate the params like that either.  
  > **username_0**: There's no JavaScript doing anything with this form. So strange...  
  > **username_1**: Sorry, just realized what the problem is. `p` is the GET parameter that your .htaccess redirect is assigning the URI path to. You’ll have to choose a different name for that param (both in the search form and the results page), since it’s conflicting with that.  
  
  ---
  
  