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

Form enctype attribute contains duplicate quotes when file field defined #408

Closed
thekenshow opened this issue Feb 19, 2020 · 3 comments
Closed
Assignees
Labels

Comments

@thekenshow
Copy link

On 1.7-rc6 I am getting a broken enctype attribute on a front-end form when a file field is defined. The resulting HTML is shown below, followed by the form yaml.

<form name="troy-apply-form" action="/careers/apply" method="POST" enctype="&quot;multipart/form-data&quot;" id="troy-apply-form" class=" troy-form">

Screen Shot 2020-02-19 at 9 07 41 AM

form:
    name: 'troy-apply-form'
    action: '/careers/apply'
    template: 'form-messages'
    classes: 'troy-form'
    fields:
        -
            name: position
            label: Position
            classes: field-control
            outerclasses: 'field-group medpaddingall nopaddingtop'
            type: text
            validate:
                required: true            
        -
            name: firstname
            label: 'First Name'
            display_label: false
            placeholder: 'Enter your first name'
            classes: field-control
            outerclasses: 'field-group medpaddingall nopaddingtop'
            type: text
            validate:
                required: true
        -
            name: lastname
            label: 'Last Name'
            display_label: false
            placeholder: 'Enter your last name'
            classes: field-control
            outerclasses: 'field-group medpaddingall nopaddingtop'
            type: text
            validate:
                required: true
        -
            name: street
            label: 'Street Address'
            display_label: false
            placeholder: 'Enter your street address'
            classes: field-control
            outerclasses: 'field-group medpaddingall nopaddingtop'
            type: text
            validate:
                required: true
        -
            name: city
            label: City
            display_label: false
            placeholder: 'Enter your city'
            classes: field-control
            outerclasses: 'field-group medpaddingall nopaddingtop'
            type: text
            validate:
                required: true
        -
            name: postalcode
            label: 'Postal Code'
            display_label: false
            placeholder: 'Enter your postal code'
            classes: field-control
            outerclasses: 'field-group medpaddingall nopaddingtop'
            type: text
            validate:
                required: true
        -
            name: phone
            label: Phone
            display_label: false
            placeholder: 'Enter your phone number'
            classes: field-control
            outerclasses: 'field-group medpaddingall nopaddingtop'
            type: text
            validate:
                required: true
        -
            name: email
            label: Email
            display_label: false
            placeholder: 'Enter your email address'
            classes: field-control
            outerclasses: 'field-group medpaddingall nopaddingtop'
            type: email
            validate:
                required: true
        -
            name: resume
            label: 'Attach your resume (a single DOC, DOCX, RTF, or PDF up to 5 Mb)'
            classes: field-control
            outerclasses: 'field-group medpaddingall nopaddingtop'
            type: file
            multiple: false
            filesize: 5
            destination: 'user/data/career_applications'
            accept:
                - application/msword
                - application/pdf
            validate:
                required: true
        -
            name: coverletter
            label: 'Attach your cover letter (a single DOC, DOCX, RTF, or PDF up to 5 Mb)'
            classes: field-control
            outerclasses: 'field-group medpaddingall nopaddingtop'
            type: file
            multiple: false
            filesize: 5
            destination: 'user/data/career_applications'
            accept:
                - application/msword
                - application/pdf
            validate:
                required: true
        -
            name: g-recaptcha-response
            label: Captcha
            type: captcha
            recaptcha_site_key: <public-key>
            recaptcha_not_validated: 'Captcha not valid!'
            validate:
                required: true
    buttons:
        -
            type: submit
            classes: btn
            value: Submit
        -
            type: reset
            classes: btn
            value: Reset
    process:
        -
            captcha:
                recaptcha_secret: <private-key>
        - 
            ip:
                label: User IP Address
        -
            email:
                subject: '[Careers Application Form] {{ form.value.firstname|e }} {{ form.value.lastname|e }}'
                body: '{% include ''forms/data.html.twig'' %}'
                to: hostmaster@example.com
                to_name: 'Careers Application'
                reply_to: '{{ form.value.email|e }}'
                attachments:
                    - coverletter
                    - resume
        -
            save:
                fileprefix: career_application-
                dateformat: Ymd-His-u
                extension: txt
                body: '{% include ''forms/data.txt.twig'' %}'
        -
            message: '{{ config.site.applyconfirm|markdown }}'
        -
            reset: true
@mahagr mahagr self-assigned this Feb 19, 2020
@mahagr mahagr added the bug label Feb 19, 2020
@rhukster
Copy link
Member

Can you try changing line 104 in user/plugins/form/templates/forms/default/form.html.twig to:

method="{{ method }}"{{ multipart|raw }}

@thekenshow
Copy link
Author

Hi - made that change and the form element renders correctly now:

<form name="troy-apply-form" action="/careers/apply" method="POST" enctype="multipart/form-data" id="troy-apply-form" class=" troy-form">

Thanks!

@ufukayyildiz
Copy link

On 1.7-rc6 I am getting a broken enctype attribute on a front-end form when a file field is defined. The resulting HTML is shown below, followed by the form yaml.

<form name="troy-apply-form" action="/careers/apply" method="POST" enctype="&quot;multipart/form-data&quot;" id="troy-apply-form" class=" troy-form">

Screen Shot 2020-02-19 at 9 07 41 AM

form:
    name: 'troy-apply-form'
    action: '/careers/apply'
    template: 'form-messages'
    classes: 'troy-form'
    fields:
        -
            name: position
            label: Position
            classes: field-control
            outerclasses: 'field-group medpaddingall nopaddingtop'
            type: text
            validate:
                required: true            
        -
            name: firstname
            label: 'First Name'
            display_label: false
            placeholder: 'Enter your first name'
            classes: field-control
            outerclasses: 'field-group medpaddingall nopaddingtop'
            type: text
            validate:
                required: true
        -
            name: lastname
            label: 'Last Name'
            display_label: false
            placeholder: 'Enter your last name'
            classes: field-control
            outerclasses: 'field-group medpaddingall nopaddingtop'
            type: text
            validate:
                required: true
        -
            name: street
            label: 'Street Address'
            display_label: false
            placeholder: 'Enter your street address'
            classes: field-control
            outerclasses: 'field-group medpaddingall nopaddingtop'
            type: text
            validate:
                required: true
        -
            name: city
            label: City
            display_label: false
            placeholder: 'Enter your city'
            classes: field-control
            outerclasses: 'field-group medpaddingall nopaddingtop'
            type: text
            validate:
                required: true
        -
            name: postalcode
            label: 'Postal Code'
            display_label: false
            placeholder: 'Enter your postal code'
            classes: field-control
            outerclasses: 'field-group medpaddingall nopaddingtop'
            type: text
            validate:
                required: true
        -
            name: phone
            label: Phone
            display_label: false
            placeholder: 'Enter your phone number'
            classes: field-control
            outerclasses: 'field-group medpaddingall nopaddingtop'
            type: text
            validate:
                required: true
        -
            name: email
            label: Email
            display_label: false
            placeholder: 'Enter your email address'
            classes: field-control
            outerclasses: 'field-group medpaddingall nopaddingtop'
            type: email
            validate:
                required: true
        -
            name: resume
            label: 'Attach your resume (a single DOC, DOCX, RTF, or PDF up to 5 Mb)'
            classes: field-control
            outerclasses: 'field-group medpaddingall nopaddingtop'
            type: file
            multiple: false
            filesize: 5
            destination: 'user/data/career_applications'
            accept:
                - application/msword
                - application/pdf
            validate:
                required: true
        -
            name: coverletter
            label: 'Attach your cover letter (a single DOC, DOCX, RTF, or PDF up to 5 Mb)'
            classes: field-control
            outerclasses: 'field-group medpaddingall nopaddingtop'
            type: file
            multiple: false
            filesize: 5
            destination: 'user/data/career_applications'
            accept:
                - application/msword
                - application/pdf
            validate:
                required: true
        -
            name: g-recaptcha-response
            label: Captcha
            type: captcha
            recaptcha_site_key: <public-key>
            recaptcha_not_validated: 'Captcha not valid!'
            validate:
                required: true
    buttons:
        -
            type: submit
            classes: btn
            value: Submit
        -
            type: reset
            classes: btn
            value: Reset
    process:
        -
            captcha:
                recaptcha_secret: <private-key>
        - 
            ip:
                label: User IP Address
        -
            email:
                subject: '[Careers Application Form] {{ form.value.firstname|e }} {{ form.value.lastname|e }}'
                body: '{% include ''forms/data.html.twig'' %}'
                to: hostmaster@example.com
                to_name: 'Careers Application'
                reply_to: '{{ form.value.email|e }}'
                attachments:
                    - coverletter
                    - resume
        -
            save:
                fileprefix: career_application-
                dateformat: Ymd-His-u
                extension: txt
                body: '{% include ''forms/data.txt.twig'' %}'
        -
            message: '{{ config.site.applyconfirm|markdown }}'
        -
            reset: true

hi, your code helped me. thank you.

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