I've created a form using amforms to ask some info about the visitor when he request a document.
I want to pass the name of the requested document in the form.

So I created the field nomDocumentEfficy and attached it to my form but I cannot get the value in my submitted forms.

Here is my form :

<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">

Whenever you submit forms to Craft, your name attribute must be formatted in a certain way by adding your values to a fields[] array. In your case, the field should look like:

<input type="hidden" name="fields[nomDocumentEfficy]" value="my_value">

You can see this happening if you ever inspect a form field inside an entry in the CMS, or if you inspect the output generated by amforms' tags you're using: {{ form.displayField('email') }}

However, not all form field types get added to this array the same as a simple text or hidden field! For reference on how to format checkbox fields, date fields, or even Matrix fields, for example, you can reference this great guide on StraightUpCraft.

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.