Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

Validating user input before save

parkerjnc
Posts: 15
Joined: Wed Sep 05, 2012 5:15 am

Validating user input before save

Unread post by parkerjnc »

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?
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: Validating user input before save

Unread post by admin »

parkerjnc,

Are item1 and 2 in a Subform or Form?

Can you post a screen capture, It might help with an answer.

Steven
parkerjnc
Posts: 15
Joined: Wed Sep 05, 2012 5:15 am

Re: Validating user input before save

Unread post by parkerjnc »

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.
Attachments
screen cap of form
screen cap of form
cap1.png (8.3 KiB) Viewed 5551 times
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: Validating user input before save

Unread post by admin »

parkerjnc,

This should help..

nuBeforeSave()

http://wiki.nubuilder.com/tiki-index.ph ... eforeSave_

Steven
parkerjnc
Posts: 15
Joined: Wed Sep 05, 2012 5:15 am

Re: Validating user input before save

Unread post by parkerjnc »

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?
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: Validating user input before save

Unread post by admin »

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
parkerjnc
Posts: 15
Joined: Wed Sep 05, 2012 5:15 am

Re: Validating user input before save

Unread post by parkerjnc »

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?
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: Validating user input before save

Unread post by admin »

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
parkerjnc
Posts: 15
Joined: Wed Sep 05, 2012 5:15 am

Re: Validating user input before save

Unread post by parkerjnc »

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.
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: Validating user input before save

Unread post by admin »

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
Post Reply