I'm trying to add a hidden input with Sprout forms and Sprout fields but I can't dynamically add a value to the input attribute.
I have a custom form template in craft/templates/_forms/field.html
in which I have the following code for the hidden field:
{%- set name = field.handle is defined ? field.handle : null %}
<input type="hidden" name="{{ name }}" value="{{ settings.value }}">
This now returns whatever value I put into the 'Hidden Field Value' input in the form builder in Craft, but if I put any dynamic data in there, e.g. {{ craft.request.path }}
(which is also the placeholder text), I get the same literal string back: "{{ craft.request.path }}". I've also tried with single braces, as I read that this might be the correct syntax, but I get the same result.
Eventually, I am wanting to set the value to {{ entry.title }}
. I read that I need to add this to my template to be able to access non-global variables {% do craft.sproutForms.addFieldVariables({ entry: entry }) %}
- does this go in the entry template just before the form, or in the form template. I get an error saying Variable "entry" does not exist
if I put it in the form template so I'm guessing it goes in the entry template.
addFieldVariables
line should go outside of your form tag. It makes the variables you are passing to it available in a more global way so that when the form is processed they can be accessed. – Ben Parizek Jan 17 '18 at 16:46