1

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.

  • Can you try using single brace syntax: {queryStr} or object syntax {{ object.queryStr }} as the Hidden Field value. – Ben Parizek May 17 '18 at 23:19
  • {queryStr} did not work, but {{ object.queryStr }} did. I'll mark the answer if you decide to post it. – Petroglyph Creative May 18 '18 at 19:25
1

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}.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.