template::form::render (private)

 template::form::render id tag_attributes

Defined in packages/acs-templating/tcl/form-procs.tcl

Render the HTML FORM tag along with a hidden element that identifies the form object.

Parameters:
id - The form identifier
tag_attributes - A name-value list of special attributes to add to the FORM tag, such as JavaScript event handlers.
Returns:
A string containing the rendered tags.

Partial Call Graph (max 5 caller/called nodes):
%3 _ _ (public) ad_log ad_log (public) ad_return_complaint ad_return_complaint (public) ad_script_abort ad_script_abort (public) export_vars export_vars (public) template::form::render template::form::render template::form::render->_ template::form::render->ad_log template::form::render->ad_return_complaint template::form::render->ad_script_abort template::form::render->export_vars

Testcases:
No testcase defined.
Source code:
    get_reference

    #----------------------------------------------------------------------
    # Check for errors on form
    #----------------------------------------------------------------------

    # make a reference to the formerror array with any validation messages
    upvar #$level $id:error $id:error

    # Clear the formerror array if it has
    # been set by another form on the same page
    upvar #$level formerror formerror
    if { [info exists formerror] } { unset formerror }

    if { [info exists $id:error] } {

        uplevel #$level "upvar 0 $id:error formerror"

        # There were errors on the form, force edit mode
        set properties(mode) edit
    }

    #----------------------------------------------------------------------
    # Buttons
    #----------------------------------------------------------------------

    if { [info exists form_properties(cancel_url)] && $form_properties(cancel_url) ne ""} {
        if {![info exists form_properties(cancel_label)] || $form_properties(cancel_label) eq ""} {
            set form_properties(cancel_label) [_ acs-kernel.common_Cancel]
        }
        lappend form_properties(edit_buttons) [list $form_properties(cancel_label) cancel]
    }

    if { [info exists form_properties(has_submit)]
         && [string is true -strict $form_properties(has_submit)]
    } {
        set form_properties(edit_buttons) {}
    }

    if { [info exists form_properties(has_edit)]
         && [string is true -strict $form_properties(has_edit)]
    } {
        set form_properties(display_buttons) {}
    }

    if { [info exists form_properties(actions)]
         && $form_properties(actions) ne ""
    } {
        set form_properties(display_buttons) $form_properties(actions)
    }

    # We keep this, so if anyone has an old form template that still loops over this multirow, it won't break hard
    # We should remove this later, maybe 6.0
    set buttons:rowcount 0

    foreach button $form_properties(${form_properties(mode)}_buttons) {
        lassign $button label name

        if {$name eq "ok"} {
        # We hard-code the OK button to be wider than it otherwise would
            set label "       $label       "
        }
        set name "formbutton:$name"

        template::element create $id $name -widget submit -label $label -datatype text
    }

    # Propagate form mode to all form elements
    foreach element_ref $elements {

        # get a reference by element ID
        upvar #$level $element_ref element

        # Check if the element has an empty string mode, and in
        # that case, set to form mode
        if {$element(mode) eq ""} {
            set element(mode) $properties(mode)
        }
    }

    # Check for errors in hidden elements
    foreach element_ref $elements {

        # get a reference by element ID
        upvar #$level $element_ref element

        if { $element(widget) eq "hidden" &&
             [info exists $id:error($element(id))] && [set $id:error($element(id))] ne ""
        } {
            # Submitting invalid data to hidden elements is a common attack vector.
            # This does not give them much information in the response.
            ad_return_complaint 1 "Your request is invalid."
            ad_log Warning "Validation error in hidden form element. This may be part of a vulnerability scan or attack reconnaissance:  '[set $id:error($element(id))]' on element '$element(id)'."
            ad_script_abort
        }
    }

    # get any additional attributes developer specified to include in form tag
    if { [info exists properties(html)] } {
        array set attributes $properties(html)
    }

    # add on or replace with attributes specified by designer in formtemplate tag
    array set attributes $tag_attributes

    # set the form to point back to itself if action is not specified
    if { ! [info exists properties(action)] } {
        set properties(action) [ns_conn url]
    }

    set output "<form id=\"$id\" name=\"$id\" method=\"$properties(method)\"
    action=\"$properties(action)\""

    ### 2/17/2007
    ### Adding a default class for forms if one does not exist
    if {![info exists attributes(class)]} {
        append output " class=\"margin-form\""
    }

    # make sure that event handlers have IDs
    foreach name [array names attributes] {
        if {[regexp -nocase {^on(.*)%} $name . event]} {
            if {![info exists attributes(id)]} {
                set attributes(id) "id[clock clicks -microseconds]"
            }
        }
    }

    # append attributes to form tag
    foreach name [array names attributes] {
        if {[regexp -nocase {^on(.*)%} $name . event]} {
            #
            # Convert automatically on$event attribute into event listener
            #
            ns_log notice "automatically adding event listener for attribute $name in form with id $id"
            template::add_event_listener  -event $event
            -id $attributes(id)  -script $attributes($name)
        } elseif {$attributes($name) eq {}} {
            append output $name"
        } else {
            append output $name=\"$attributes($name)\""
        }
    }

    append output ">"

    ### 2/11/2007
    ### Adding Form Fieldset legend and attributes
    if { [info exists properties(fieldset)] } {
        # Fieldset
        append output " <fieldset"
        array set fs_attributes [lindex $properties(fieldset) 0]
        if {![info exists fs_attributes(class)]} {
            append output " class=\"form-fieldset\""
        }
        foreach name [array names fs_attributes] {
            if {$fs_attributes($name) eq {}} {
                append output $name"
            } else {
                append output $name=\"$fs_attributes($name)\""
            }
        }
        append output ">"

        # Legend
        set fieldset_legend [lindex $properties(fieldset) 1]
        append output "<legend>$fieldset_legend</legend>"
    }

    # Include exported variables created by ad_form when specifying
    # the -export flag
    if { [info exists form_properties(exported_vars)] } {
        append output {<!-- Exported form vars START -->}
        append output $form_properties(exported_vars)
        append output {<!-- Exported form vars END -->}
    }

    # Export form ID and current form mode
    append output [export_vars -form { { form\:id $id } { form\:mode $properties(mode) } }]

    # If we're in edit mode, output the action
    upvar #$level $id:formaction formaction
    if { $properties(mode) eq "edit"
         && [info exists formaction]
         && $formaction ne ""
    } {
        upvar #$level $id:formaction action
        append output [export_vars -form { { form\:formaction $formaction } }]
    }

    return $output
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ]
Show another procedure: