Index: openacs.org-dev/packages/acs-tcl/tcl/form-processing-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs.org-dev/packages/acs-tcl/tcl/form-processing-procs.tcl,v diff -u -r1.1 -r1.2 --- openacs.org-dev/packages/acs-tcl/tcl/form-processing-procs.tcl 9 Jul 2002 17:34:59 -0000 1.1 +++ openacs.org-dev/packages/acs-tcl/tcl/form-processing-procs.tcl 12 Dec 2002 12:31:41 -0000 1.2 @@ -27,9 +27,29 @@ In general the full functionality of the form builder is exposed by ad_form, but with a much more user-friendly and readable syntax and with state management handled automatically. + +
+ In order to make it possible to use ad_form to build common form snippets within procs, code + blocks are executed at the current template parse level. This is necessary if validate and + similar blocks are to have access to the form's contents but may cause surprises for the + unwary. So be wary. +
+ On the other hand when subst is called, for instance when setting values in the form, the + caller's level is used. Why do this? A proc building a common form snippet may need to + build a list of valid select elements or similarly compute values that need to be set in + the form, and these should be computed locally. + +
+ + Yes, this is a bit bizarre and not necessarily well thought out. The semantics were decided + upon when I was writing a fairly complex package for Greenpeace, International and worked well + there so for now, I'm leaving them the way they are. + +
+ Here's an example of a simple page implementing an add/edit form:
@@ -42,12 +62,12 @@ my_table_key:optional } - ad_form -name form_name -form { + ad_form -name form_name -export {foo {bar none}} -form { my_table_key:key(my_table_sequence) - {value:text(textarea) {{label "Enter text"} - {html {rows 4 cols 50}}}} + {value:text(textarea) {label "Enter text"} + {html {rows 4 cols 50}}} } -select_query { select value from my_table where my_table_key = :my_table_key } -validate { @@ -62,18 +82,16 @@ values (:key, :value)" ad_returnredirect "somewhere" - return + ad_script_abort } -edit_data { db_dml do_update " update my_table set value = :value where my_table_key = :key" ad_returnredirect "somewhere" - return + ad_script_abort } - gp_return_template -
@@ -85,7 +103,7 @@
- The call to gp_return_template then renders the page - it is your responsibility to render the form + The call to ad_return_template then renders the page - it is your responsibility to render the form in your template by use of the ATS formtemplate tag.
@@ -105,11 +123,25 @@
+ General information about parameters + +
Parameters which take a name (for instance "-name" or "-select_query_name") expect a simple name + not surrounded by curly braces (in other words not a single-element list). All other parameters expect + a single list to be passed in. +
+ Here's a complete list of switches that are supported by ad_form:
+
This must be the first switch passed into ad_form +
-
+
@@ -261,9 +294,9 @@
- {my_key:text(multiselect),multiple {{label "select some values"} + {my_key:text(multiselect),multiple {label "select some values"} {options {first second third fourth fifth}} - {html {size 4}}}} + {html {size 4}}}@@ -273,7 +306,7 @@
- {hide_me:text(hidden) {{value 3}}} + {hide_me:text(hidden) {value 3}}Define the hidden form element "hide_me" with the value 3 @@ -312,7 +345,7 @@ } set valid_args { form method action html name select_query select_query_name new_data on_refresh - edit_data validate on_submit confirm_template new_request edit_request }; + edit_data validate on_submit confirm_template new_request edit_request export}; ad_arg_parser $valid_args $args @@ -340,7 +373,7 @@ foreach valid_arg $valid_args { if { [info exists $valid_arg] } { if { [info exists af_parts(${form_name}__$valid_arg)] && - ![lsearch { form name validate } $valid_arg] == -1 } { + ![lsearch { form name validate export } $valid_arg] == -1 } { return -code error "Form \"$form_name\" already has a \"$valid_arg\" section" } @@ -350,7 +383,7 @@ # and validation block to be extended, for now at least until I get more experience # with this ... - if { [lsearch { name form method action html validate } $valid_arg ] == -1 } { + if { [lsearch { name form method action html validate export } $valid_arg ] == -1 } { set af_parts(${form_name}__extend) "" } } @@ -360,10 +393,9 @@ return -code error "No \"form\" block has been specified for form \"$form_name\"" } - # If we're not extending + # If we're not extending - this needs integration with the ATS form builder ... if { !$extend_p } { - global gp_conn - incr gp_conn(form_count) + # incr ad_conn(form_count) } #################### @@ -480,6 +512,17 @@ } + if { [info exists export] } { + foreach value $export { + set name [lindex $value 0] + if { [llength $value] == 1 } { + template::element create $form_name $name -datatype text -widget hidden -value [uplevel [list set $name]] + } else { + template::element create $form_name $name -datatype text -widget hidden -value [uplevel [list subst [lindex $value 1]]] + } + } + } + # We need to track these for submission time and for error checking global af_type @@ -572,7 +615,9 @@ help_text - label - format - - value { + value - + before_html - + after_html { if { [llength $extra_arg] > 2 || [llength $extra_arg] == 1 } { return -code error "element $element_name: \"$extra_arg\" requires exactly one argument" } @@ -739,7 +784,7 @@ foreach {element_name validate_expr error_message} $validate_element { if { ![template::element error_p $form_name $element_name] && \ ![uplevel #$level [list expr $validate_expr]] } { - template::element set_error $form_name $element_name $error_message + template::element set_error $form_name $element_name [uplevel [list subst $error_message]] } } } @@ -829,7 +874,7 @@ ad_form. @param element The name of the element - @parma value The value to set + @param value The value to set } { upvar #[template::adp_level] __ad_form_values__ values @@ -854,9 +899,9 @@ foreach arg $args { if { [llength $arg] == 1 } { upvar $arg value - gp_set_element_value -element $arg $value + ad_set_element_value -element $arg $value } else { - gp_set_element_value -element [lindex $arg 0] [lindex $arg 1] + ad_set_element_value -element [lindex $arg 0] [lindex $arg 1] } } }