When submitting a custom form in D8, it keeps on giving me:

"Submission failed. Please reload the page, ensure JavaScript is enabled and try again."

It does correctly switch the /antibot form action upon mousemovement.

But i still end up with this error.

I have been searching the issue queue, but cant seem to find any docs/reference to this.

The form is submitted via a regular submit button (so, not submitted programatically).

Any help would be much appreciated.

Issue fork antibot-3247315

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

guardian87 created an issue. See original summary.

gaurav.kapoor’s picture

Is the console showing any JS errors when you are on the form page?

guardian87’s picture

No JS errors displayed.

I have uninstalled the module for now, as it renders my forms unusable, in the sense that nobody can submit them anymore...

gaurav.kapoor’s picture

Did you try reinstalling the module, the issue goes away for most of the users after that.

guardian87’s picture

Yes we did.
No difference...

guardian87’s picture

To whom it may concern.
When rendering a custom form, on a field by field basis, you need to make sure to render:

{{ form.antibot_key }}
{{ form.antibot_no_js }}

That solved it.

gaurav.kapoor’s picture

Component: Code » Documentation
Issue tags: +Novice

@guardian87 Thanks for sharing this information. I will keep this issue open and use it for improving the documentation.

gaurav.kapoor’s picture

seppe beelprez’s picture

Had the same issue when updated to 1.5, happened on a custom form with field by field basis. Adding form.antibot_no_js didn't solved it.

For now I have to go back using 1.4

jonas-gerosa361’s picture

Assigned: Unassigned » jonas-gerosa361

I will take a look at it.

gaurav.kapoor’s picture

Component: Documentation » Code
Issue tags: -Novice
jonas-gerosa361’s picture

Assigned: jonas-gerosa361 » Unassigned
gaurav.kapoor’s picture

Version: 8.x-1.4 » 8.x-1.5
seppe beelprez’s picture

What I mentioned in #9 isn't a problem anymore. I assume it had something to do with another module. My apologies!

camslice’s picture

I'm facing the same issue on a custom user registration form. Was working fine until the v1.5 upgrade, so I've downgraded back to v1.4 for the time being. Drupal 9.3.2, PHP 7.4.25

I'm including the antibot key in a twig template called "form.html.twig" like so:

{% block form %}
  <form{{ attributes }}>
    {{ element['antibot_key'] }}
    {{ children }}
  </form>
{% endblock %}
gaurav.kapoor’s picture

Version: 8.x-1.5 » 2.0.x-dev
seppe beelprez’s picture

I had this issue again recently and I noticed that I had printed the {{ attributes }} twice in the same twig template #facepalm, so I thought to post this here as well in case anyone did something the same as me.

jumpsuitgreen’s picture

Antibot Module version: 2.0.2
Drupal Version: 9.3.12

I had custom Webforms that weren't working on a site with the Antibot module enabled and protection enabled in the Webforms settings. Once I included {{ element.antibot_no_js }}{{ element.antibot_key }} in the form Twig template, everything worked fine. I only needed to include it once in the template and I did so at the very bottom with some of the other hidden fields like form_token and form_id. This bit of information is no where in the documentation unless I missed it somewhere. Preferably, the module page and the README file. Here is what my block looks like the the bottom of the webform Twig template:

            <div class="row">
                <div class="col-md-2 offset-md-1 offset-lg-2">
                    {{ element.elements.message }}
                    {{ element.elements.url_redirection }}
                    {{ element.form_build_id }}
                    {{ element.form_token }}
                    {{ element.form_id }}
                    {{ element.elements.actions }}
                    # Antibot keys to render.
                    {{ element.antibot_no_js }}
                    {{ element.antibot_key }}
                </div>
            </div>
        </div>
</form>
fpc_drupal’s picture

#18 Worked for my custom forms! Thank you very much jumpsuitgreen! Pretty incredible that this solution was posted at the exact time as I was having the problem.

ronalpha’s picture

form_id was returning null or empty when executing form validation logic.
This code _antibot_generate_key($form['#form_id']); in antibot.module

Changed to
_antibot_generate_key($form_state->getValue('form_id'));
Now the form_id is returning the correct value and the form is processed with no antibot related errors.

danrod’s picture

Assigned: Unassigned » danrod

danrod’s picture

I included the instructions for the fix from #18 in the README.md file in this MR.

Can be reviewed anytime.

danrod’s picture

Status: Active » Needs review
danrod’s picture

I'll merge this, it's just documentation changes.

Thank you everyone.

danrod’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

danrod’s picture

Assigned: danrod » Unassigned