Forum
Perch Forms
Hello Support.
I followed this tutorial in the following link below so that upon submitting the form on my website the page wouldn't refresh.
https://forum.grabaperch.com/forum/08-08-2014-forms-app-js-and-page-refresh
This is working fine and it is posting to the perch backend etc however I am wondering if it's possible to display validation error messages without refreshing the page?
Once the form submit I get a success message but it would be a nice touch to get the validation messages also if a field was filled in incorrectly.
Is this possible to do?
Many thanks for any help in advance.
The only way would be to submit the form via ajax and update the DOM accordingly.
Hello Drew
Thanks for your response - could you give me some more information regarding this / possibly point me in the right direction on how I would achieve this.
I have attached my code below -
Code for form
Script for submitting form without page refresh
Thanks for your help.
How is it failing?
It's not failing at present. It's posting the form to the backend but no success message is appearing and no validation errors are appearing if an attempt is made to submit the form without filling in the all the fields.
You need to look at the HTML that is turned. Find the form, and then update the page with the new form HTML.
I turned off the HTML5 validation, and commented out the script to stop the page refreshing etc. and when I clicked submit the page refreshed but none the error messages appeared. I also checked the page source and I could see all the code for the form but not the perch:error tags. Any ideas why this is happening?
If you turn on debug, do you get any validation errors being flagged?
When I submit the form with debug switched on I get the following -
Those are the required fields that need to be completed for the form to submit.
Any idea why the validation errors aren't being pulled through when the form is submitted with the fields empty.
I would suggest that you get a basic Perch form working without any JavaScript. You can then see what you need to implement in your script to replace that.