Hi All,
This is the first time I've played with ad_form. Mostly, it's neat, but dates are making me a little bit crazy. (Ok, after about 4 hours of fighting with dates, dates are making me REALLY crazy.) This is the 4.6.2-beta tarball, with PostgreSQL 7.2.3.
Here's what's in the db:
select * from ptk_reports ;
report_id | user_id | report_text | filed_date | reported_date
-----------+---------+-------------+------------+---------------
13 | | new | | 1988-02-07
Here's the ad_form code:
ad_page_contract {
Simple add/edit form
} {
report_id:optional
{reported_date ""}
}
ad_form -name ptk_report -form {
report_id:key(ptk_report_seq)
{report_text:text(textarea) {label "Activity"} {html {rows 4 cols 50}}}
{reported_date:date,to_sql(linear_date_no_time),from_sql(linear_date_no_time)
{label "Date of activity"}
{format "MONTH DD YYYY"}
{value {$reported_date}}
}
} -select_query {
select report_text, reported_date from ptk_reports where report_id = :report_id
} -validate {
{report_text
{[string length $report_text] >= 3}
"\"Your report\" must be a string containing three or more characters"
}
} -new_data {
db_dml do_insert "
insert into ptk_reports
(report_id, report_text, reported_date)
values
(nextval('ptk_report_seq'), :report_text, :reported_date)"
} -edit_data {
db_dml do_update "
update ptk_reports
set report_text = :report_text,
reported_date = :reported_date
where report_id = :report_id "
} -after_submit {
ad_returnredirect "/"
ad_script_abort
}
ad_return_template
This works fine for putting data into the db, but when I view existing data (by adding ?report_id=13 to the url), I don't get anything pre-selected for the dates.
I also tried changing to from_sql(sql_date), which gets me the date string (as 1988-02-07) in the year entry, and nothing selected for month or day.
Is this something ad_form is supposed to be able to do, and if so, how? I think I see how to do it with the form builder code (I had a peek at the calendar package), but how to do it with ad_form has me stumped.
TIA.