Forum OpenACS Development: Form validation of dates

Collapse
Posted by Henry Ma on
Hi, I'm using ad_form procedure to create a form that has a date type widget eg.

{date_close:date,from_sql(sql_date),to_sql(sql_date),to_html(sql_date) \
{label From}
}

When this is displayed, the entire date is displayed in year field rather than correctly filled. Also when I submit the form, the sql query generated is invalid:

date_close = 'to_date(''2005 11 26'', ''YYYY MM DD'')'

How should I fix up these problems?

Collapse
Posted by Jose Pablo Escobedo Del Cid on
Hi Henry,

I use the date template in the ad_form like this:

{due_date:date,to_sql(linear_date),from_sql(sql_date),optional
{label "label"}
{format "MONTH DD YYYY HH24 MI SS"}
{today}
{help}
{value {default date in format mm dd yyyy hh24 mi ss, using template::util::date::create}}
}

and before inserting into de database, you have to convert the date to a valid format, like this: (my data type is timestamp)

set due_date_ansi [db_string set_date "select to_timestamp('[template::util::date::get_property linear_date $due_date]','YYYY MM DD HH24 MI SS')"

and that's it, I hope this helps.

Regards,

jopez