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 @@

Developer's Guide fo ad_form

- 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 @@

  • Executing the form Through the -extend switch, you can declare the form in multiple steps, adding elements. - But as soon as you add an action block (on_submit, after_submit, new_data, edit_data, etc.), + But as soon as you add an action block (on_submit, after_submit, new_data, edit_data, etc.), ad_form will consider the form complete, and execute the form, meaning validating element values, - and executing the action blocks. The execution will happen automatically the first time you + and executing the action blocks. The execution will happen automatically the first time you call ad_form with an action block, and after that point, you cannot -extend the form later. Also, if you don't supply any action blocks at all, the form will never be considered finished, and thus validation will not get executed. Instead, you will get an error when the form is rendered. - +

    - Bottom line: + Bottom line:

    1. You must always have at least one action block, even if it's just -on_submit { }.
    2. You cannot extend the form after you've supplied any action block.
    - +

    @@ -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 @@

    -action

    The name of the script to be called when the form is submitted. Defaults to the name of the script - being served. + being served.

    -actions

    -

    A list of lists of actions (e.g. {{" Delete " delete} {" Resolve " resolve}} ), which gets - translated to buttons at the bottom of the form. You can find out what button was pressed +
    A list of lists of actions (e.g. {{" Delete " delete} {" Resolve " resolve}} ), which gets + translated to buttons at the bottom of the form. You can find out what button was pressed with [template::form get_action form_id], usually in the -edit_request block to perform whatever actions you deem appropriate. When the form is loaded the action will be empty.
    - +

    -mode { display | edit }

    -

    If set to 'display', the form is shown in display-only mode, where the user cannot edit the fields. - Each widget knows how to display its contents appropriately, e.g. a select widget will show - the label, not the value. If set to 'edit', the form is displayed as normal, for editing. - Defaults to 'edit'. Switching to edit mode when a button is clicked in display mode is handled +
    If set to 'display', the form is shown in display-only mode, where the user cannot edit the fields. + Each widget knows how to display its contents appropriately, e.g. a select widget will show + the label, not the value. If set to 'edit', the form is displayed as normal, for editing. + Defaults to 'edit'. Switching to edit mode when a button is clicked in display mode is handled automatically
    - +

    -has_edit { 0 | 1 }

    -

    Set to 1 to suppress the Edit button automatically added by the form builder. Use this if you +
    Set to 1 to suppress the Edit button automatically added by the form builder. Use this if you include your own.

    -has_submit { 0 | 1 }

    -

    Set to 1 to suppress the OK button automatically added by the form builder. Use this if you +
    Set to 1 to suppress the OK button automatically added by the form builder. Use this if you include your own.

    -method

    -

    The standard METHOD attribute to specify in the HTML FORM tag at the beginning of the rendered +
    The standard METHOD attribute to specify in the HTML FORM tag at the beginning of the rendered form. Defaults to POST.
    @@ -258,16 +258,16 @@

    -export

    This options allows one to export data in current page environment to the page receiving the form. - Variables are treated as "hidden" form elements which will be automatically generated. Each value is - either a name, in which case the Tcl variable at the caller's level is passed to the form if it exists, + Variables are treated as "hidden" form elements which will be automatically generated. Each value is + either a name, in which case the Tcl variable at the caller's level is passed to the form if it exists, or a name-value pair. - The behavior of this option replicates that for 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.
    - +

    -select_query

    Defines a query that returns a single row containing values for each @@ -287,21 +287,21 @@

    -show_required_p { 0 | 1 }

    -

    Should the form template show which elements are required. Use 1 or t for true, 0 or f for false. +
    Should the form template show which elements are required. Use 1 or t for true, 0 or f for false. Defaults to true.

    -on_request

    A code block which sets the values for each element of the form meant to be modifiable by the user when the built-in key management feature is being used or to define options for - select lists etc. Set the values as local variables in the code block, and they'll get + select lists etc. Set the values as local variables in the code block, and they'll get fetched and used as element values for you. This block is executed every time the form is loaded except when the form is being submitted (in which case the -on_submit block is executed.)

    -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. Any variables set in an -edit_request @@ -339,26 +339,26 @@
    When the form is submitted, this code block will be executed before any new_data or edit_data code block. Use this if your form doesn't interact with the database or if the database type involved includes a Tcl API that works for both new and existing data. The values of the form's elements will be available as local variables. - Calling 'break' inside this block causes the submission process to be aborted, and neither new_data, edit_data, nor - after_submit will get executed. Useful in combination with template::form set_error to display an error on a form + Calling 'break' inside this block causes the submission process to be aborted, and neither new_data, edit_data, nor + after_submit will get executed. Useful in combination with template::form set_error to display an error on a form element.

    -new_data

    This code block will be executed when a form for a new database row is submitted. This block should insert the data into the database or create a new database object or content repository item containing the data. - Calling 'break' inside this block causes the submission process to be aborted, and - after_submit will not get executed. Useful in combination with template::form set_error to display an error on a form + Calling 'break' inside this block causes the submission process to be aborted, and + after_submit will not get executed. Useful in combination with template::form set_error to display an error on a form element.

    -edit_data

    This code block will be executed when a form for an existing database row is submitted. This block should update the database or create a new content revision for the existing item if the data's stored in the content repository. - Calling 'break' inside this block causes the submission process to be aborted, and - after_submit will not get executed. Useful in combination with template::form set_error to display an error on a form + Calling 'break' inside this block causes the submission process to be aborted, and + after_submit will not get executed. Useful in combination with template::form set_error to display an error on a form element.
    @@ -422,15 +422,15 @@ element create procedure are allowed.

    - +