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.
Validating user input before save
-
- Posts: 15
- Joined: Wed Sep 05, 2012 5:15 am
Validating user input before save
I cannot seem to find any good examples of using custom code in the Before Save for a form. What I would like to do is check the value of item#1 in the form and if it is a certain value make sure the value of item#2 has not already been used in another record in the database table. If the value of item#2 is found in the database table then show some kind of warning message on the form. I am not clear on how the code specified here can interact with the form. Is this possible?
Re: Validating user input before save
parkerjnc,
Are item1 and 2 in a Subform or Form?
Can you post a screen capture, It might help with an answer.
Steven
Are item1 and 2 in a Subform or Form?
Can you post a screen capture, It might help with an answer.
Steven
-
- Posts: 15
- Joined: Wed Sep 05, 2012 5:15 am
Re: Validating user input before save
item 1 and 2 are both in the same form.
The screen cap attached shows the form which just has a few tabs and on the General tab is a field for Package ID and one for Request Type. If Request Type is "New" then I want to check and make sure the value for Package ID has not been given previously. If it is "Update" then it is ok to allow the Package ID to already exist in the table. My thinking was that I could put some code in the "Before Save" portion of the Custom Code to perform the check and somehow return the user to the General tab if the check fails. Just not quite sure how to manage that.
The screen cap attached shows the form which just has a few tabs and on the General tab is a field for Package ID and one for Request Type. If Request Type is "New" then I want to check and make sure the value for Package ID has not been given previously. If it is "Update" then it is ok to allow the Package ID to already exist in the table. My thinking was that I could put some code in the "Before Save" portion of the Custom Code to perform the check and somehow return the user to the General tab if the check fails. Just not quite sure how to manage that.
You do not have the required permissions to view the files attached to this post.
Re: Validating user input before save
parkerjnc,
This should help..
nuBeforeSave()
http://wiki.nubuilder.com/tiki-index.ph ... eforeSave_
Steven
This should help..
nuBeforeSave()
http://wiki.nubuilder.com/tiki-index.ph ... eforeSave_
Steven
-
- Posts: 15
- Joined: Wed Sep 05, 2012 5:15 am
Re: Validating user input before save
I guess where I'm getting hung up is mixing php and JavaScript on the form.
I need to run php code to query the database using the value of a field on the form that I can get with javascript. Is there an example of the nuBeforeSave() which queries the database?

Re: Validating user input before save
parkerjnc,
I have a few questions,
Where does the Package ID come from?
Is it from a sticker or can it be automatically generated.
Are there only 2 request types? If so do you really need it at all? It could be automatically set to Update if there is a matching ID.
Steven
I have a few questions,
Where does the Package ID come from?
Is it from a sticker or can it be automatically generated.
Are there only 2 request types? If so do you really need it at all? It could be automatically set to Update if there is a matching ID.
Steven
-
- Posts: 15
- Joined: Wed Sep 05, 2012 5:15 am
Re: Validating user input before save
No, the package id can not be automatically generated. It is generated through another more manual mechanism.
There are several different request types, although I only need to ensure "New" is not used more than once for a given package id. The request type is a drop down with options from a table in the database. Ideally, if a package id is entered that has already been used, I would have some kind of visual indicator on the form. Then when they engage the drop down, it would not have the New option. Is this possible?
There are several different request types, although I only need to ensure "New" is not used more than once for a given package id. The request type is a drop down with options from a table in the database. Ideally, if a package id is entered that has already been used, I would have some kind of visual indicator on the form. Then when they engage the drop down, it would not have the New option. Is this possible?
Re: Validating user input before save
parkerjnc,
nuBeforeSave() won't do what you are asking, but can I suggest that on After Save you see if there is another Package ID of the same number and if so set Request Type to "Update".
Steven
nuBeforeSave() won't do what you are asking, but can I suggest that on After Save you see if there is another Package ID of the same number and if so set Request Type to "Update".
Steven
-
- Posts: 15
- Joined: Wed Sep 05, 2012 5:15 am
Re: Validating user input before save
Unfortunately that won't work either. I am basically trying to prevent a user from being sloppy and reusing a package id unintentionally. I need to be able to let them know that package id has already been used so they can come up with a different one. My real problem is that I don't control the package id creation so I have to accommodate whatever the user enters while helping them to not screw up.
Re: Validating user input before save
Joe,
The only thing I can suggest is that you let the record be saved, test it in After Save but return a message in a Text Object that there was a problem and that it needs to filled in correctly.
Steven
The only thing I can suggest is that you let the record be saved, test it in After Save but return a message in a Text Object that there was a problem and that it needs to filled in correctly.
Steven