Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Forms & Blueprints

Form has already been send after an invalid form submition

form

Started by Kjell 5 years ago · 3 replies · 963 views
5 years ago

Hi everybody,

Update: Improved readability of snippet

I have a question about forms that are used by visitors of the website. When this visitor enters the information in the form but a field inside the form is invalid. After the user has updated the invalid field and tries to resubmit. It shows this message: "This form has already been submitted.". I cannot submit this form unit I go to another page and go back to the form.

I have been looking in the PHP files that show this message and found that there is an id set that checks if it is a new or old form/submission. This is what my file looks like:

YAML
---
title: Contact

form:
    name: contact-form
    fields:
        name:
            label: Name
            placeholder: 'Enter your name'
            autocomplete: 'off'
            type: text
            validate:
                required: true
        company:
            label: Company name
            placeholder: 'Enter your company name'
            type: text
            validate:
                required: false
        email:
            label: Email
            placeholder: 'Enter your email address'
            type: email
            validate:
                required: true
        phoneNumber:
            label: Phone number
            placeholder: 'Enter your phone number address'
            type: tel
            validate:
                required: false
        demoSubject:
            type: checkboxes
            label: Select a subject
            default:
                option-one: false
                option-two: false
            options:
                option-one: CrisisSuite
               option-two Social media trainer
            use: keys
            validate:
                required: true
            classes: checkboxes
        g-recaptcha-response:
            type: captcha
            label: Captcha
            recaptcha_not_validated: 'Captcha is not valid'
    buttons:
        submit:
            type: submit
            value: Submit
            classes: primary-button
    process:
        captcha: true
        email:
            from: '{{ config.plugins.email.from }}'
            to: '{{ config.plugins.email.to }}'
            subject: 'some message'
            body: "{% include 'forms/data.html.twig' %}"
        redirect: en/contact/thankyou
---

Does anybody know how I can resolve this isuee?

I am using Grav version: 1.7.3 and PHP version: 7.4.14. This is a modular contact form. Any suggestions are welcome and I can give more information if needed 😃

last edited 01/25/21 by pamtbaau
5 years ago

@Pannakoek, Please help the community help you...

A small and well appreciated effort would be to properly format code/yaml snippets using triple backticks (```). And while you are at it, also please use proper indentation.

<pre>

YAML
---
title: Contact
form:
   name: contact-form
   fields:
     name:
     etc.
---

</pre>

5 years ago

@pamtbaau This is indeed better to read.

YAML
---
title: Contact

form:
    name: contact-form
    fields:
        name:
            label: Name
            placeholder: 'Enter your name'
            autocomplete: 'off'
            type: text
            validate:
                required: true
        company:
            label: Company name
            placeholder: 'Enter your company name'
            type: text
            validate:
                required: false
        email:
            label: Email
            placeholder: 'Enter your email address'
            type: email
            validate:
                required: true
        phoneNumber:
            label: Phone number
            placeholder: 'Enter your phone number address'
            type: tel
            validate:
                required: false
        demoSubject:
            type: checkboxes
            label: Select a subject
            default:
                option1: false
                option2: false
            options:
                option1: CrisisSuite
                option2: Social media trainer
            use: keys
            validate:
                required: true
            classes: checkboxes
        g-recaptcha-response:
            type: captcha
            label: Captcha
            recaptcha_not_validated: 'Captcha is not valid'
    buttons:
        submit:
            type: submit
            value: Submit
            classes: primary-button
    process:
        captcha: true
        email:
            from: '{{ config.plugins.email.from }}'
            to: '{{ config.plugins.email.to }}'
            subject: 'Email subject'
            body: "{% include 'forms/data.html.twig' %}"
        redirect: en/contact/thankyou
---
👍 1
5 years ago

I had the same issue. After submit, when you get errors, you can't resubmit correctly filled form, because it says same form was already submitted. But as I was aiming for AJAX form, I didn't bother with figuring out what's wrong

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Ton Haarmans, 5 years ago
13 1145 4 months ago
Forms & Blueprints · by Hugo Oliveira, 5 months ago
0 67 5 months ago
Forms & Blueprints · by Flachy Joe, 6 months ago
9 142 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 118 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 136 7 months ago