Could you please help me with this minor problem?
I have read the documentation of ad_form but I believe I am stuck 😟( Basically, I am trying to find out how ad_form works and have build a small silly app from the documentation code examples that uploads recipes into a database table. Table contains Title, Description and Category of the Recipe.
I want to use the ad_form to enter Title,Description and
Category(by selecting the Category select box on the form)
The problem is that the form complains that Category is required even after I've selected a value from
the select box.
For the sake of simplicity, title, description and category_id are all text datatype. Category_id gets values from another table and I use db_list_of_lists to bring them in.
I read from the docs that I can build the select box using the option "-on_request" and that works fine.
Now do I have to set the form value category_id using: the option "-in_submit"? I used "ad_set_element_value..." to no avail. But...Title and description have no problem getting set.
Ok, this is a silly example but do I do wrong ?
Thanks a million in advance!
The code for the form is:
ad_page_contract {
Simple add/edit form
This is a simple form to add recipe information into our table
} {
my_table_key:optional
}
set foo_options [db_list_of_lists foo_option_list "select category_id from categories" ]
ad_form -name add_recipe -form {
my_table_key:key(recipes_id_seq)
{title:text,nospell {label "Title"}
{html {size 40}}}
{description:text(textarea) {label "Enter the description of your recipe"} {html {rows 3 cols 50} } }
} -validate {
{description
{[string length description] >= 3}
"\"description\" must be a string containing three or more characters"
}
} -on_request {{category_id:text(select) {label "Which Category"} {options $foo_options}}
} -on_submit {
ad_set_element_value -element category_id $category_id
} -new_data {
db_dml do_insert "insert into recipes (title,description,category_id) values (:title,:description,:category_id)"
} -after_submit {
# ad_returnredirect "somewhere"
ad_script_abort
}