Home
The Toolkit for Online Communities
17244 Community Members, 0 members online, 2152 visitors today
Log In Register
OpenACS Home : Forums : OpenACS Q&A : ad_form select fields howto : One Message

Forum OpenACS Q&A: Validating dates in ad_form

Collapse
Posted by Stan Kaufman on
What is the syntax for checking in the "-validate" block the date a user sends back from a date widget? I can't figure this out from ad_form's docs or from the source code.

For instance, the following creates a form and initializes the date widget to today:

set now [db_string now_str "select to_char(current_timestamp,'YYYY-MM-DD') from dual"]

ad_form -name test_form -form {
  my_table:key
  {name:text(text) {label "Name"} {html {size 50}}}
  {start_date:date {label "Start Date"} {value $now}}
} -validate {
  {start_date {start_date:date} }
}
...etc...

But while this successfully flags the date field with an appropriate message ("The day must be between 1 and 30 for the month of September") when you set the widget to "31 September 2002", it dies ugly when a correct date is passed in:

Request Error

       syntax error in expression "start_date:date"
           while executing
       "expr start_date:date"
           ("uplevel" body line 1)
           invoked from within
       "uplevel #$level [list expr $validate_expr"
           (procedure "ad_form" line 455)
...etc...

I was hoping for some good examples in other packages, but none of them (other than survey and acs-person) seem to use ad_form yet, and those don't use dates. News does use dates of course but not ad_form. Furthermore, it interestingly only checks for a valid interval and happily allows a user to enter a bogus "publish date" -- and then barfs ugly with a Request Error (not a more graceful ad_return_error) when [clock scan] can't parse the date.

So, is there a simple syntax that I'm missing here, or does the issue involve the "to_sql", "from_sql" and "to_html" stuff that I haven't yet figured out either? Many TIA!