Go to URL only if form is submitted

Hello,

I have few input-fields on my page which I submit to database on button click. I made it by visual interface, no coding. Some of the fields are required*.

Then I added code to forward a user to a certain URL from DB:

const itemUrl = $w( ‘#dynamicDataset’ ).getCurrentItem().links;
wixLocation.to(itemUrl);

and I noticed, that it redirect to the URL despite the fact that user doesn’t fill all required* fields.

How can I cross check with DB if those fields are written, and only after that redirect?

Thanks…

See: https://www.wix.com/corvid/reference/wix-dataset/dataset/onaftersave

Thanks J.D.