Display error message and stop execution

How I can display an error message to the user and stop the execution of the form.

Look at the article Adding Submit Messages to Your Form which will get you started.

You can also play with the Form Examples in your editor to see how they work.

Tanks, but it doesn’t help.
I’m checking some content in a collection in the "on ready function of a form, and in some cases, I would like to send an error message to the user before the user start filling the form.
In general, I would like also to know how to send a specific error message if a user input is not correct.
I’m aware about the submit error & success messages, but that’s not what I’m looking for.

In the onReady(), when you’re checking the content in the collection, if there’s a problem, you could open up a Lightbox to notify the user of a problem. You can then redirect to another page, or perform some other action.

Thanks, this may help, but I have no idea how to code the redirect page. I couldn’t find an example.

You can use wix-location.to() for the redirect. See the examples.

When you open the Lightbox, you can also get the close, and do the redirect there:

import wixLocation from "wix-location";
import wixWindow from "wix-window";

wixWindow.openLightbox("LightboxName")
   .then( (data) => {
   let receivedData = data; // returned data if needed
   wixLocation.to("/something-interesting");
} );

I hope this helps,

Yisrael

Thanks, I will try and let you know.

@yisrael-wix The article you linked to isnt’t there. Any reason? Altnernative?

Guess things changed. Try these instead: