Index: openacs-4/packages/acs-tcl/tcl/form-processing-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/form-processing-procs.tcl,v diff -u -r1.16.2.8 -r1.16.2.9 --- openacs-4/packages/acs-tcl/tcl/form-processing-procs.tcl 16 Feb 2003 23:59:08 -0000 1.16.2.8 +++ openacs-4/packages/acs-tcl/tcl/form-processing-procs.tcl 5 Mar 2003 14:40:42 -0000 1.16.2.9 @@ -149,6 +149,10 @@ being served. +

-cancel_url

+

The URL the cancel button should take you to. If this is specified, a cancel button will show up. +
+

-html

The given html will be added to the "form" tag when page is rendered. This is commonly used to define multipart file handling forms. @@ -179,9 +183,16 @@

-edit_request

A code block which sets the values for each element of the form meant to be modifiable by the user. Use - this when a single query to grab database values is insufficient. + this when a single query to grab database values is insufficient. You just need to set the values as local + variables in the code block, and they'll get fetched and used as element values for you.
+

-new_request

+

A code block which initializes elements for a new row. Use this to set default values. + You just need to set the values as local + variables in the code block, and they'll get fetched and used as element values for you. +
+

-confirm_template

The name of a confirmation template to be called before any on_submit, new_data or edit_data block. When the user confirms input control will be passed to the appropriate submission block. The confirmation @@ -320,11 +331,11 @@
-    start_date:date,to_sql(sql_date),from_html(sql_date),optional
+    start_date:date,to_sql(sql_date),to_html(sql_date),optional
     

Define the optional element "start_date" of type "date", get the sql_date property before executing - any new_date, edit_date or on_submit block, set the sql_date property after performing any + any new_data, edit_data or on_submit block, set the sql_date property after performing any select_query.

@@ -349,9 +360,9 @@ return -code error "No arguments to ad_form" } - set valid_args { form method action html name select_query select_query_name new_data on_refresh + set valid_args { form method action mode html name select_query select_query_name new_data on_refresh edit_data validate on_submit after_submit confirm_template new_request edit_request - export}; + export cancel_url cancel_label has_edit actions }; ad_arg_parser $valid_args $args @@ -389,7 +400,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 export } $valid_arg ] == -1 } { + if { [lsearch { name form method action html validate export mode cancel_url has_edit actions } $valid_arg ] == -1 } { set af_parts(${form_name}__extend) "" } } @@ -425,6 +436,10 @@ array set af_element_parameters [list] if { [info exists form] } { + + # Remove comment lines in form section (DanW) + regsub -all -line -- {^\s*\#.*$} $form "" form + foreach element $form { set element_name_part [lindex $element 0] @@ -470,16 +485,20 @@ set af_validate_elements($form_name) [list] if { [info exists validate] } { + + # Remove comment lines in validate section (DanW) + regsub -all -line -- {^\s*\#.*$} $validate "" validate + foreach validate_element $validate { if { [llength $validate_element] != 3 } { return -code error "Validate block must have three arguments: element name, expression, error message" } - if { [lsearch $af_element_names($form_name) [lindex $validate_element 0]] == -1 } { - return -code error "Element \"[lindex $validate_element 0]\" is not a form element" + if { [lsearch $af_element_names($form_name) [lindex $validate_element 0]] == -1 } { + return -code error "Element \"[lindex $validate_element 0]\" is not a form element" } lappend af_validate_elements($form_name) $validate_element - } + } } if { !$extend_p } { @@ -493,10 +512,30 @@ lappend create_command "-method" $method } + if { [info exists mode] } { + lappend create_command "-mode" $mode + } + + if { [info exists cancel_url] } { + lappend create_command "-cancel_url" $cancel_url + } + + if { [info exists cancel_label] } { + lappend create_command "-cancel_label" $cancel_label + } + if { [info exists html] } { lappend create_command "-html" $html } + if { [info exists has_edit] } { + lappend create_command "-has_edit" $has_edit + } + + if { [info exists actions] } { + lappend create_command "-actions" $actions + } + # Create the form eval $create_command @@ -624,9 +663,14 @@ help_text - label - format - + mode - value - + section - before_html - - after_html { + after_html - + result_datatype - + search_query - + search_query_name { if { [llength $extra_arg] > 2 || [llength $extra_arg] == 1 } { return -code error "element $element_name: \"$extra_arg\" requires exactly one argument" } @@ -692,16 +736,16 @@ return -code error "Edit request block conflicts with select query" } ad_page_contract_eval uplevel #$level $edit_request - - # set form vars from edit_request block + # set form vars from edit_request block foreach element_name $af_element_names($form_name) { if { [llength $element_name] == 1 } { if { [uplevel \#$level [list info exists $element_name]] } { set values($element_name) [uplevel \#$level [list set $element_name]] } } - } + } + } else { # The key exists, grab the existing values if we have an select_query clause @@ -752,6 +796,14 @@ if { [info exists new_request] } { ad_page_contract_eval uplevel #$level $new_request + # LARS: Set form values based on local vars in the new_request block + foreach element_name $af_element_names($form_name) { + if { [llength $element_name] == 1 } { + if { [uplevel \#$level [list info exists $element_name]] } { + set values($element_name) [uplevel \#$level [list set $element_name]] + } + } + } } }