I tried using the -edit_request block of ad_form and I was surprised that I couldn't just set a form variable and have the result show up in the initial presentation of the form. Searching through the code-base, I noticed that the survey package uses the ad_set_form_values proc to set the default values in the form from within the -edit_request block. This behavior is different from the other ad_form blocks which seem to have access to all of the form variables and the variables declared in ad_page_contract which are created at the template level. To make the behavior more regular, I modified ad_form so that form variables set in the -edit_request block are are set in the initial presentation of the form without requiring the user to call ad_set_form_values or ad_set_element_value. So instead of doing this (this assumes that "description" is a form paramter):
} -edit_request {
set description "blah blah blah"
ad_set_element_value -element description $description
}
a user could just do this:
} -edit_request {
set description "blah blah blah"
}
This is more intuitive, and it will be less likely to trip up new users of ad_form.
The change involves a slight change to the -edit_request processing that copies parameter values from the template level to the __ad_form_values__ array which holds the current value of the form variables. The change is shown below (after the ad_page_contract_eval):
ad_page_contract_eval uplevel #$level $edit_request
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]]
}
}
}
If nobody has a problem with this change. I will change ad_form and fix the affected code in the survey package.