Form has already been send after an invalid form submition

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:

---
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 :smiley:

@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.

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

@pamtbaau This is indeed better to read.

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

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