Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Using Before Save / Field validation

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
icoso
Posts: 181
Joined: Sun Feb 07, 2021 11:09 pm
Been thanked: 1 time

Using Before Save / Field validation

Unread post 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?
Last edited by kev1n on Thu Jun 17, 2021 7:37 am, edited 1 time in total.
Reason: Updated subject, removed upper case
kev1n
nuBuilder Team
Posts: 4301
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Using Before Save / Field validation

Unread post 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.
kev1n
nuBuilder Team
Posts: 4301
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: USING BEFORE SAVE

Unread post 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.
Post Reply