Forum .LRN Q&A: Dynamical Forms

Collapse
Posted by Laetitia Duby on
Hi all !

I'm trying to build a form with a combobox which elements are extracted from the database. I have a table "books" and a table "articles". I want to reference a book in an "article" object : I have in the "article" table an attribute "article_book" that is a foreign key to the "book_id" attribute of the "book" table.

Here is the form (I replaced the book name and id where I want the objects of the database) :
ad_form -form {
	myarticle_id:key
	{myarticle_title:text \
		{label "Title"}
		{html {size 30 maxlength 50 }}
	}
	{myarticle_journal:text \
		{label "Journal"}
		{html {size 40 maxlength 100 }}
	}
	{myarticle_sum:text(textarea) \
		{label "Summary"}
		{html {rows 10 cols 30 }}
	}
	{myarticle_book:text(select) \
		{label "Included in : "}
		{options {{{<book_title>} <book_id>} {{<book_title>} <book_id>}  {{<book_title>} <book_id>}}} \
		{values <book_id>}
	}
}
My problem is how can I do a query and use its results in the options clause of the select element. I looked in the demo directory of acs_templating but it couldn't help. Any ideas ?

Laetitia
Collapse
2: Re: Dynamical Forms (response to 1)
Posted by Laetitia Duby on
After a look at the acs-lang tcl files, I added a variable as :
set list_of_books [db_list_of_lists books_loop { select mybook_title, book_id from mybooks order by mybook_title }]
And I reference this variable in the form :
{myarticle_book:text(select) \
		{label "Included in : "}
		{options $list_of_books} 
}
But an error appears and I don't understand it :
can't read "element(options)": no such element in array
    while executing
"template::widget::menu  $element(name) $element(options) $element(values) attributes $element(mode)"
    (procedure "template::widget::select" line 11)
    invoked from within
"template::widget::$element(widget) element $tag_attributes"
    (procedure "template::element::render" line 10)
    invoked from within
"template::element::render add_art myarticle_book {  }"
    ("eval" body line 1)
    invoked from within
"eval template::element::$command $form_id $element_id $args"
    (procedure "template::element" line 2)
    invoked from within
"template::element render ${form:id} myarticle_book {  } "
    invoked from within
"append __adp_output "[template::element render ${form:id} myarticle_book {  } ]""
    ("uplevel" body line 185)
Does someone know what I'm doing wrong ?

Laetitia