Question:
How to ensure that a velo code is only executed in the event when a submit button is successful (ie all mandatory fields are filled by the site visitor) - this is for input fields connected to a CMS.
Product:
Wix Studio
What are you trying to achieve:
I have “built” a “form”, that is actually a set of input fields connecting to a CMS (so, not a classic “form”, but enabled through CMS). It includes a submit button that puts all the input data into a CMS. There are some fields that are set to required inputs, such as obvious ones like ‘name’ and ‘email address’ etc.
(the submit button is defined through "click actions connects to ‘submit’, and a success message is being displayed)
All this is working well and as intended.
Then, I have added a velo code that is executed once the submit button is clicked (see below how it is implemented ). The aim of the code is to send an email to the site visitor [‘triggeredEmails’] and some additional features such as opening a lightbox [wixWindowFrontend.openLightbox(…)] etc
Basically, the code itself is running well, too!
However, the velo code is being executed at all circumstances when the submit button in clicked, even if some mandatory inputs are have not been done by the visitor.
The code starts with:
$w.onReady(function () {
$w(“#submit-button”).onClick(() => {
…
…
});
I do understand that the code is executed, as there is no “check” if the all the required fields are filled by the site visitor.
Finally, what I want to achieve:
So, I’d like to ensure that the code is only executed once the submit button is successful (or in other words: when the success message is being showed up, not for the “failure” message).
I am wonderig how to implement this - is it something that can be realized through/in the code or even straight in the editor?
Perhaps I can somehow implment an another query to check the visibilty of the success message (that is another text element with an ID)
Any ideas are more than welcome!
What have you already tried:
- Fields are implemented and well connected to CMS, submit button in place
- Code is executed when clicked