Forum OpenACS Q&A: ad_form validation

Collapse
Posted by manny quinto on
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?
Collapse
2: Re: ad_form validation (response to 1)
Posted by Don Baccus on
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.

Collapse
3: Re: ad_form validation (response to 1)
Posted by Randy O'Meara on
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.

Randy