Page 1 of 1

Using Before Save / Field validation

Posted: Thu Jun 17, 2021 2:14 am
by icoso
I have some fields on my form that I want to make sure that they are completely filled in according to a certain format. They can't be entered partially. They must be a certain length and format BEFORE I can save them to the database.
For example a phone number.
I have a field for phone number that MUST be entered as ###-###-#### I do not want them to enter the number as ###-####.

Where in the form can I put the code to check the length and format of this field BEFORE SAVING it and if it is not entered exactly according to the format, I do not want to allow them to save the data. Should this be done in JAvascript (The forms custom code) or should this be done int he BEFORE SAVE code (which is PHP - sever side) ALL I want to happen is if the user clicks the save buttonm then the validation of the screen data occurs. if it fails, then I want to return to the edit screen with a JavaScript alert displayed.

I've done this many times with my own custom forms that I've built, using java script, but I don't know how to do it with the SAVE button in nuBuilder running its own function. How can I run this JavaScript to cancel the Save function when the user clicks it if my field validation fails?

Re: Using Before Save / Field validation

Posted: Thu Jun 17, 2021 5:41 am
by kev1n
Use either the JavaScript nuBeforeSave() to do a client-side validation. Check out the Code Library for a snippet. There's event a minimal example in (Builders->) "Code Snippets"

Since a client-side validation is not secure (JavaScript can be modified or bypassed if you know how), consider a server-side validation.
Use the BS (Before Save) event and call nuDisplayError() to show an error when the validation fails.

Re: USING BEFORE SAVE

Posted: Thu Jun 17, 2021 6:20 am
by kev1n
kev1n wrote:Use either the JavaScript nuBeforeSave() to do a client-side validation. Check out the Code Library for a snippet. There's event a minimal example in (Builders->) "Code Snippets"

Since a client-side validation is not secure (JavaScript can be modified or bypassed if you know how), consider a server-side validation.
Use the BS (Before Save) event and call nuDisplayError() to show an error when the validation fails.
In both cases, this is going to happen:
if it fails, then I want to return to the edit screen with a JavaScript alert displayed.