Forum OpenACS Q&A: ad_form validation
Posted by manny quinto on 07/12/03 10:32 AM
How do you validate a form input from a database before submission? I would want to check if the input is unique from a postgresql database and display an error if it is -so that the user would know about it. An error is being flagged by postgresql in the logs when a user inputs a value which is already in the database. How do I inform a freindly message to the user about it (instead of a bomb) while using ad_form?
2: Re: ad_form validation (response to 1)
Posted by Don Baccus on 07/13/03 12:33 AM
One possibility is to include an on_error clause and within it, check for duplicate values for those fields declared UNIQUE.
In this way you avoid accessing the database in the case where there are no unique violations.
3: Re: ad_form validation (response to 1)
Posted by Randy O'Meara on 07/14/03 04:04 AM
To expand on Don's response...
If you have the latest pg database driver, the error condition will be described in the global tcl variable "errorInfo". You can use a regex to extract the constraint name that is associated with the unique constraint violation. That is, if you have named your constraints.