<p>The value you place in your Hidden Field settings gets treated as a template and whatever values you pass o the <code>addFieldVariables</code> method are treated as the object that gets parsed by that template.</p>

<p>Just like, when you load an Entry page in Craft, Craft provides the <code>entry</code> variable to the template, when we process the Hidden Field settings, Sprout Forms provides the <code>addFieldVariables</code> variables to that template.</p>

<p>While Craft knows it is giving you an Entry and names it's variable <code>entry</code>, Sprout Forms doesn't really know what you might be giving it, so it names the variable available to your settings template a generic term: <code>object</code>.</p>

<p>You can access these values using Object Syntax, in the same way you can using the Title Format behavior for Sections:</p>

<pre><code>{{ object.variableName }}
</code></pre>

<p>Or in your case:</p>

<pre><code>{{ object.queryStr }}
</code></pre>

<p>In some cases, you can also use a shorthand to output the value with a single curly brace: <code>{queryStr}</code>.</p>

CC BY-SA 4.0
2018-05-18T19:58:04.157Z
2018-05-18T19:58:04.157Z
Ben Parizek
<p>I have the following code:</p>

<pre><code>    {% set query = {} %}

     {% if not craft.request.getParam('q')|length %}
          {#.. key, value pairing .. #}
          {% set query = query | merge({(key):(value)}) %}
     {% else %}
          {% set query = craft.request.getParam('q') %}
     {% endif %}

     {% set queryStr = query|join(' OR ') %}

     {% do craft.sproutForms.addFieldVariables({ queryStr: queryStr }) %}   

     {{ craft.sproutForms.displayForm('requestcsv') }}
</code></pre>

<p>When I add {{queryStr}} to my hidden field in requestcsv, it doesn't populate. I can output {{queryStr}} on the page, and even so, it doesn't get passed.</p>

<p>Is there something I'm missing in order to be able to pass this string to a hidden field? {{queryStr}} is just a plain string.</p>

CC BY-SA 4.0
2018-05-17T23:19:36.463Z
Can you try using single brace syntax: `{queryStr}` or object syntax `{{ object.queryStr }}` as the Hidden Field value.
Ben Parizek
CC BY-SA 4.0
2018-05-18T19:25:09.447Z
{queryStr} did not work, but  {{ object.queryStr }} did. I'll mark the answer if you decide to post it.
Caroline from Aquarian
<plugin-sproutforms>
addFieldVariables not functioning with string data
# addFieldVariables not functioning with string data

(Asked by: username_0 on 2018-05-17)

I have the following code:
    {% set query = {} %}

     {% if not craft.request.getParam('q')|length %}
          {#.. key, value pairing .. #}
          {% set query = query | merge({(key):(value)}) %}
     {% else %}
          {% set query = craft.request.getParam('q') %}
     {% endif %}

     {% set queryStr = query|join(' OR ') %}

     {% do craft.sproutForms.addFieldVariables({ queryStr: queryStr }) %}   

     {{ craft.sproutForms.displayForm('requestcsv') }}

When I add {{queryStr}} to my hidden field in requestcsv, it doesn't populate. I can output {{queryStr}} on the page, and even so, it doesn't get passed.
Is there something I'm missing in order to be able to pass this string to a hidden field? {{queryStr}} is just a plain string.

**Tags:** plugin-sproutforms

> **Comments:**
> **username_1**: Can you try using single brace syntax: `{queryStr}` or object syntax `{{ object.queryStr }}` as the Hidden Field value.  
> **username_0**: {queryStr} did not work, but  {{ object.queryStr }} did. I'll mark the answer if you decide to post it.  

---

## 1 answers

### Answer by username_1 on 2018-05-18. Score: 1 | Accepted answer

The value you place in your Hidden Field settings gets treated as a template and whatever values you pass o the addFieldVariables method are treated as the object that gets parsed by that template.
Just like, when you load an Entry page in Craft, Craft provides the entry variable to the template, when we process the Hidden Field settings, Sprout Forms provides the addFieldVariables variables to that template.
While Craft knows it is giving you an Entry and names it's variable entry, Sprout Forms doesn't really know what you might be giving it, so it names the variable available to your settings template a generic term: object.
You can access these values using Object Syntax, in the same way you can using the Title Format behavior for Sections:
{{ object.variableName }}

Or in your case:
{{ object.queryStr }}

In some cases, you can also use a shorthand to output the value with a single curly brace: {queryStr}.


---

