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.17 -r1.18 --- openacs-4/packages/acs-tcl/tcl/form-processing-procs.tcl 9 Oct 2002 13:34:33 -0000 1.17 +++ openacs-4/packages/acs-tcl/tcl/form-processing-procs.tcl 30 Nov 2002 17:23:55 -0000 1.18 @@ -522,7 +522,9 @@ foreach value $export { set name [lindex $value 0] if { [llength $value] == 1 } { - template::element create $form_name $name -datatype text -widget hidden -value [uplevel [list set $name]] + if { [uplevel [list info exists $name]] } { + template::element create $form_name $name -datatype text -widget hidden -value [uplevel [list set $name]] + } } else { template::element create $form_name $name -datatype text -widget hidden -value [uplevel [list subst [lindex $value 1]]] } @@ -581,10 +583,11 @@ return -code error "element $element_name: \"$flag\" attribute must have a parameter" } set name af_$flag - append name "($element_name)" + append name "(${form_name}__$element_name)" if { [info exists $name] } { return -code error "element $element_name: \"$flag\" appears twice" } + global $name set $name $af_element_parameters($element_name:$flag) } @@ -639,10 +642,6 @@ # 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 - global af_from_sql - global af_to_sql - global af_to_html - foreach element_name $af_element_names($form_name) { if { [llength $element_name] == 1 } { if { [info exists af_from_sql(${form_name}__$element_name)] } { @@ -740,6 +739,10 @@ return -code error "Couldn't get the next value from sequence \"$af_sequence_name($form_name)\"" } set values(__new_p) 1 + + if { [info exists new_request] } { + ad_page_contract_eval uplevel #$level $new_request + } } set values(__key_signature) [ad_sign "$values($key_name):$form_name"] @@ -910,37 +913,34 @@ foreach arg $args { if { [llength $arg] == 1 } { upvar $arg value - ad_set_element_value -element $arg $value + ad_set_element_value -element $arg -- $value } else { - ad_set_element_value -element [lindex $arg 0] [lindex $arg 1] + ad_set_element_value -element [lindex $arg 0] -- [lindex $arg 1] } } } ad_proc -public ad_form_new_p { - -key + -key:required } { This is for pages built with ad_form that handle edit and add requests in one file. - It determines wether the current request is for editing an existing item, - in which case it returns 0, or adding a new one, which will return 1. + It returns 1 if the current form being built for the entry of new data, 0 if for + the editing of existing data.

- For this to work there needs to be an element defined in the form that is of - the ad_form pseudo datatype "key". If you don't specify -key then this proc - will try to guess it from the existing variables - if there is exactly one that - ends on _id then it takes that one, otherwise you have to specify it manually. + It does not make sense to use this in pages that don't use ad_form.

- It does not make sense to use this in pages that don't use ad_form. + @param key The database key for the form, which must be declared to be of type "key"

Example usage:

-    if { [ad_form_new_p] } {
+    if { [ad_form_new_p -key item_id] } {
         ad_require_permission $package_id create
         set page_title "New Item"
     } else {
@@ -954,43 +954,7 @@
 } {
 
     set form [ns_getform]
-    if { [empty_string_p $form] } {
-        # no form. assume new
-        return 1
-    }
     
-    if { ![info exists key] } {
-        # no key name given. loop through form and try to guess one
+    return [expr {[empty_string_p $form] || [ns_set find $form $key] == -1 || [ns_set get $form __new_p] == 1 }]
 
-        for { set i 0 } { $i < [ns_set size $form] } { incr i } {
-            
-            if { [regexp {_id$} [ns_set key $form $i]] } {
-                # this could be a key
-                
-                if { [info exists key] } {
-                    # we found one before already, bad. throw an error
-                    unset key
-                    break
-                }
-                set key [ns_set key $form $i]
-            }
-        }
-        if { ![info exists key] } {
-            ad_return_error "ad_form_new_p failed" "Could not guess key element. Please specify it by using \"ad_form_new_p -key your_key_id\"."
-            ad_script_abort
-        }
-    }
-
-    if { [ns_set find $form $key] == -1 } {
-        # no key
-        return 1
-    }
-
-    if { [ns_set get $form __new_p] == 1 } {
-        # there is a key, but __new_p is also set
-        return 1
-    }
-    
-    # not new
-    return 0
 }