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?
Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
Using Before Save / Field validation
Using Before Save / Field validation
Last edited by kev1n on Thu Jun 17, 2021 7:37 am, edited 1 time in total.
Reason: Updated subject, removed upper case
Reason: Updated subject, removed upper case
-
- nuBuilder Team
- Posts: 4305
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 446 times
- Contact:
Re: Using Before Save / Field validation
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.
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.
-
- nuBuilder Team
- Posts: 4305
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 446 times
- Contact:
Re: USING BEFORE SAVE
In both cases, this is going to happen: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.
if it fails, then I want to return to the edit screen with a JavaScript alert displayed.