Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In first line of a Bolt form, there is a duplicate 'name=' #269

Closed
gwbonline opened this issue Oct 28, 2018 · 5 comments
Closed

In first line of a Bolt form, there is a duplicate 'name=' #269

gwbonline opened this issue Oct 28, 2018 · 5 comments
Assignees
Labels

Comments

@gwbonline
Copy link

I'm using the newest version of Boltforms. I noticed in the first line of code of the form, the name attribute is mentioned twice. What is the purpose of that? According to a html validator, it is an error and I want to remove it. What file do I need to edit for this?

@michaelborn
Copy link

What does your boltforms.bolt.yml config file look like? I'm not seeing this double name attribute myself.

@gwbonline
Copy link
Author

gwbonline commented Oct 30, 2018

The config file does contain only once the name of the form and that is 'contact'. But why does the form in the source code contains two times this name? When visiting this url, you can look at the source code:
https://validator.w3.org/nu/?doc=http%3A%2F%2Fbeta.hetfestijn.nl%2F

debug:
    enabled: false
    address: info@willembosma.nl
csrf: true
contact:
    submission:
        ajax: true
    notification:
        enabled: true
        debug: false
        debug_address: name@example.com
        debug_smtp: true
        subject: 'Message'
        from_name: name
        from_email: email
        replyto_email: email
        replyto_name: name
        to_name: 'Bericht afkomstig van'
        to_email: info@test.nl
    feedback:
        success: 'Uw bericht is verzonden'
        error: 'Er is iets misgegaan. Probeer het nog een keer'
    fields:
        name:
            type: text
            options:
                required: true
                label: Naam
                constraints:
                    - NotBlank
                    -
                        Length:
                            min: 3
                            max: 128
        email:
            type: text
            options:
                required: true
                label: E-mailadres
                
                constraints:
                    - NotBlank
                    - Email
        message:
            type: textarea
            options:
                required: true
                label: Bericht
        submit:
            type: submit
            options:
                label: Verzenden
                attr:
                    class: 'button primary'

@michaelborn
Copy link

Hmm. Are you using a custom template? What does your embed twig function look like?

https://bolt.github.io/boltforms/templates.html

@gwbonline
Copy link
Author

gwbonline commented Nov 4, 2018

The only thing I've changed is the appearance of the message that the recipient receives. And in my templates I call the form with {{ boltforms('contact') }}.

An example of the website is beta.hetfestijn.nl

@jadwigo
Copy link
Collaborator

jadwigo commented Nov 5, 2018

It's a bug - in line https://github.com/bolt/boltforms/blob/4.2/templates/form/_form_theme.twig#L326 the form renders the form name, and all attributes .. where the name probably is repeated as a key in attr of the form too:

{%- block form_start -%}
    {%- do form.setMethodRendered() -%}
    {% set method = method|upper %}
    {%- if method in ["GET", "POST"] -%}
        {% set form_method = method %}
    {%- else -%}
        {% set form_method = "POST" %}
    {%- endif -%}
    <form name="{{ name }}" 
        method="{{ form_method|lower }}"
        {% if action != '' %} action="{{ action }}"{% endif %}
        {% for attrname, attrvalue in attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}
        {% if multipart %} enctype="multipart/form-data"{% endif %}>
    {%- if form_method != method -%}
        <input type="hidden" name="_method" value="{{ method }}" />
    {%- endif -%}
{%- endblock form_start -%}

So this part repeats the name:

{% for attrname, attrvalue in attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}

The quickest fix is probably the fowlling:

  • copy the templates directory (with all subdirectories) to your theme directory (I usually copy everything because the templates have a lot of dependencies within this directory)
  • change the form configuration to use the templates in your theme (also all of them, as above)
  • modify the form_start macro in forms/_form_theme.twig by removing the name="{{ name }}" part:
{%- block form_start -%}
    {%- do form.setMethodRendered() -%}
    {% set method = method|upper %}
    {%- if method in ["GET", "POST"] -%}
        {% set form_method = method %}
    {%- else -%}
        {% set form_method = "POST" %}
    {%- endif -%}
    <form
        method="{{ form_method|lower }}"
        {% if action != '' %} action="{{ action }}"{% endif %}
        {% for attrname, attrvalue in attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}
        {% if multipart %} enctype="multipart/form-data"{% endif %}>
    {%- if form_method != method -%}
        <input type="hidden" name="_method" value="{{ method }}" />
    {%- endif -%}
{%- endblock form_start -%}

Please double check if this works, because I have not tested this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants