[SOLVED] Submit Form via JS

Hey guys! I have a problem with submitting a form in JavaScript with Neos. Submitting the form via the button works, the hash in the URL changes and I get the confirmation.

Using “document.querySelector(’#contact-form’).submit();” on the same form: Refreshes the page with the correct URL hash but I get no confirmation message and the form doesn’t change.

Is there anything I am missing here? I am using a very simple form (like the one described in the official How-To).

Hello Burak,

in a Form of the neos/form package, the submit buttons contain the __currentPage to jump to, as in

<input type="button" name="__currentPage" value="{form.nextPage.index}">Submit</input>

That is required in order to allow next and previous buttons that both submit the form and jump to the corresponding page.

If you just submit the form via JS, the __currentPage will not be sent and you stay on the first form page.
You could send the form via sth like document.querySelector('#contact-form .next .btn').click() or – if there is only one page – by adding a hidden field that sets __currentPage to 1

Thanks for the input Bastian, now it works. I was implementing invisible Recaptcha, that is why I needed to submit the form with JS.

I took a different approach and hid the “real” button, made my own button that triggers a click on the real button after my verification.