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.78 -r1.79 --- openacs-4/packages/acs-tcl/tcl/form-processing-procs.tcl 28 Dec 2018 11:24:10 -0000 1.78 +++ openacs-4/packages/acs-tcl/tcl/form-processing-procs.tcl 5 Feb 2019 15:09:15 -0000 1.79 @@ -19,10 +19,10 @@
- We use the standard OpenACS Templating System (ATS) form builder's form and element create - procedures to generate forms, and its state-tracking code to determine when to execute - various code blocks. Because of this, you can use any form builder datatype or widget - with this procedure, and extending its functionality is a simple matter of implementing + We use the standard OpenACS Templating System (ATS) form builder's form and element create + procedures to generate forms, and its state-tracking code to determine when to execute + various code blocks. Because of this, you can use any form builder datatype or widget + with this procedure, and extending its functionality is a simple matter of implementing new ones. Because ad_form is just a wrapper for the ATS, you must familiarize yourself with it to be able to use ad_form effectively. @@ -41,21 +41,21 @@
- Bottom line: + Bottom line:
@@ -99,20 +99,20 @@ ad_form -name form_name \ -export { - foo - {bar none} + foo + {bar none} many_values:multiple signed_var:sign big_array:array } -form { my_table_key:key(my_table_sequence) - - {value:text(textarea) + + {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 { @@ -121,17 +121,17 @@ "\$value\" must be a string containing three or more characters" } } -on_submit { - + foreach val $many_values { # do stuff } - + if {[info exists big_array(some_key)]} { set some_value $big_array(some_key) } - + set safe_verified_value $signed_var - + } -new_data { db_dml do_insert " insert into my_table @@ -161,7 +161,7 @@ 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. - +
On submission, the validation block checks that the user has entered at least three characters into the @@ -205,36 +205,36 @@
-
-
-
-
-
vars
argument in proc
- export_vars, which in turn follows specification
+ The behavior of this option replicates that for vars
argument in proc
+ export_vars, which in turn follows specification
for input page variables in ad_page_contract.
- In particular, flags :multiple
, :sign
and :array
are allowed and
+ In particular, flags :multiple
, :sign
and :array
are allowed and
their meaning is the same as in export_vars
.
-
-
- +
template::data::validate::float
on this list implements the 'float' datatype.
template::widget::radio
implements the 'radio' widget.
+ For example, the procedure template::widget::radio
implements the 'radio' widget.
Not all widgets are compatible with all datatypes.
Define a multiple select element with five choices, in a four-line select box. @@ -514,7 +514,7 @@ Define the optional element "start_date" of type "date", get the sql_date property before executing any new_data, edit_data or on_submit block, set the sql_date property after performing any - select_query. + select_query.
@@ -552,12 +552,12 @@ if { [llength $args] == 0 } { return -code error "No arguments to ad_form" - } + } 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 on_request new_request edit_request export cancel_url cancel_label - has_submit has_edit actions edit_buttons display_buttons show_required_p + has_submit has_edit actions edit_buttons display_buttons show_required_p on_validation_error fieldset }; ad_arg_parser $valid_args $args @@ -589,7 +589,7 @@ foreach valid_arg $valid_args { if { [info exists $valid_arg] } { - if { [info exists af_parts(${form_name}__$valid_arg)] + if { [info exists af_parts(${form_name}__$valid_arg)] && $valid_arg ni { form name validate export } } { return -code error "Form \"$form_name\" already has a \"$valid_arg\" section" @@ -631,13 +631,13 @@ # or extend block on the fly set element_names [list] - array set af_element_parameters [list] + 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] @@ -697,7 +697,7 @@ } set element_name [lindex $validate_element 0] - if {$element_name ni $af_element_names($form_name) + if {$element_name ni $af_element_names($form_name) && ![template::element::exists $form_name $element_name] } { return -code error "Element \"$element_name\" is not a form element" @@ -886,7 +886,7 @@ } } } - + foreach extra_arg $af_extra_args($element_name) { lappend form_command "-[lindex $extra_arg 0]" [uplevel [list subst [lindex $extra_arg 1]]] } @@ -896,7 +896,7 @@ } # Check that any acquire and get_property attributes are supported by their element's datatype - # These are needed at submission and fill-the-form-with-db-values time + # These are needed at submission and fill-the-form-with-db-values time foreach element_name $af_element_names($form_name) { if { [llength $element_name] == 1 } { if { [info exists af_from_sql(${form_name}__$element_name)] } { @@ -975,14 +975,14 @@ 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 if { ![info exists select_query] && ![info exists select_query_name] } { - return -code error "Key \"$key_name\" has the value \"[set $key_name]\" but no select_query, select_query_name, or edit_request clause exists. (This can be caused by having ad_form request blocks in the wrong order.)" + return -code error "Key \"$key_name\" has the value \"[set $key_name]\" but no select_query, select_query_name, or edit_request clause exists. (This can be caused by having ad_form request blocks in the wrong order.)" } if { [info exists select_query_name] } { @@ -1026,7 +1026,7 @@ return -code error "Couldn't get the next value from sequence: $errmsg\"" } set values(__new_p) 1 - + 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 @@ -1036,15 +1036,15 @@ set values($element_name) [uplevel \#$level [list set $element_name]] } } - } + } } } set values(__key_signature) [ad_sign -- "$values($key_name):$form_name"] } foreach element_name $properties(element_names) { if { [info exists values($element_name)] } { - if { [info exists af_flag_list(${form_name}__$element_name)] + if { [info exists af_flag_list(${form_name}__$element_name)] && "multiple" in $af_flag_list(${form_name}__$element_name) } { template::element set_values $form_name $element_name $values($element_name) @@ -1054,7 +1054,7 @@ } } - } elseif { [template::form is_submission $form_name] } { + } elseif { [template::form is_submission $form_name] } { # Handle form submission. We create the form values in the caller's context and execute validation # expressions if they exist @@ -1063,12 +1063,12 @@ # in a reasonable way. foreach element_name $properties(element_names) { - if { [info exists af_flag_list(${form_name}__$element_name)] + if { [info exists af_flag_list(${form_name}__$element_name)] && "multiple" in $af_flag_list(${form_name}__$element_name) } { set values [uplevel #$level [list template::element get_values $form_name $element_name]] uplevel #$level [list set $element_name $values] -# "get_values $values" + # "get_values $values" } else { set value [uplevel #$level [list template::element get_value $form_name $element_name]] uplevel #$level [list set $element_name $value] @@ -1077,10 +1077,10 @@ # Update the clicked button if it does not already exist uplevel #$level { - if {![exists_and_not_null ${__submit_button_name}]} { - set ${__submit_button_name} ${__submit_button_value} - } + if {[info exists __submit_button_name && $__submit_button_name ne ""]} { + set $__submit_button_name $__submit_button_value } + } if { [info exists key_name] } { upvar #$level $key_name __key @@ -1097,8 +1097,8 @@ foreach validate_element $af_validate_elements($form_name) { foreach {element_name validate_expr error_message} $validate_element { - if { ![template::element error_p $form_name $element_name] - && ![uplevel #$level [list expr $validate_expr]] + if { ![template::element error_p $form_name $element_name] + && ![uplevel #$level [list expr $validate_expr]] } { template::element set_error $form_name $element_name [uplevel [list subst $error_message]] } @@ -1114,7 +1114,7 @@ # elements is a common attack vector, we react harsh if we see # an invalid input here. # - if {![string is boolean -strict $__refreshing_p] + if {![string is boolean -strict $__refreshing_p] || ![string is boolean -strict $__confirmed_p] } { ad_return_complaint 1 "Your request is invalid." ns_log Warning "Validation error in hidden form element.\ @@ -1129,7 +1129,7 @@ ad_page_contract_eval uplevel #$level $on_refresh } } else { - # Not __refreshing_p + # Not __refreshing_p if { [template::form is_valid $form_name] } { @@ -1239,7 +1239,7 @@ error "Unknown return code: $errno" } } - + } elseif { [info exists on_validation_error] } { uplevel #$level $on_validation_error } @@ -1255,7 +1255,7 @@ -element:required value } { - Set the value of a particular element in the current form being built by + Set the value of a particular element in the current form being built by ad_form. @param element The name of the element @@ -1337,4 +1337,3 @@ # tcl-indent-level: 4 # indent-tabs-mode: nil # End: -