am-impact / amforms

Forms plugin for Craft
Other
122 stars 21 forks source link

Add hidden field value #146

Closed migswd closed 7 years ago

migswd commented 7 years ago

I want to add a hidden field in my form with a value that I pass on. How could I do that ?

Here below is my form code

<div class="form-askemail contact">
    {{ getCsrfInput() }}

    {# This should always be here! #}
    <input type="hidden" name="action" value="/amForms/submissions/saveSubmission">

    {# Insert your form's handle. #}
    <input type="hidden" name="handle" value="{{ form.handle }}">

    {# This will namespace your inputs (for IDs and such), but it's not required though #}
    <input type="hidden" name="namespace" value="{{ form.getNamespace() }}">

    {# Optional: Redirect URL. Will redirect to current page by default. #}
    <input type="hidden" name="redirect" value="{{ craft.request.getParam('redirect') }}">

    {# Optional: Anti-spam protection. #}
    {{ craft.amForms.displayAntispam() }}

    {# Optional: Google reCAPTCHA protection. #}
    {{ craft.amForms.displayRecaptcha() }}

    {# Place the HTML of your fields here #}
    {{ form.displayField('email') }}
    {{ form.displayField('societe') }}
    {{ form.displayField('typeEtablissementAskEmailForm') }}
    {{ form.displayField('numeroDepartement') }}

    {# Hidden input field with my value #}
    <input type="hidden" name="nomDocumentEfficy" value="my_value">
</div>
hubertprein commented 7 years ago

Assuming that nomDocumentEfficy is the handle of your hidden field:

<input type="hidden" name="{{ form.getNamespace() }}[fields][nomDocumentEfficy]" value="my_value">