Forum OpenACS Q&A: template::form::set_values not working?!

Collapse
Posted by tammy m on

Hi

I am confused by why this works for me:

template::element set_properties $form_name first_name -value $ad_content(first_name)
template::element set_properties $form_name first_name -values [list $ad_content(first_name)]

But this does not

    template::form::set_values $form_name ad_content

Yet if I print out the array, the values are in the FORM. From the associated adp page:

<table>
  <tr>
    <td>
     @ad_content.first_name@
    </td>

    <td>
      @ad_content.last_name@
    </td>
    
    <td>
      @ad_content.email@
    </td>
  </tr>
</table>

What I am missing here?! All the calls are made from the same tcl page, in the same FORM. The values are filled in the array passed to template::form::set_values . Yet only the value I set with template::element set_properties appear in the FORM on the associated adp page... I can print out the values in the ad_content array on that page though.

Help! argh.

Collapse
Posted by tammy m on
Ok

This seems to be related to Templating code throwing undocumented errors again...

It looks like template::element::get_reference throws an error (this is documented, however this is a private helper proc and all procs that call it don't document that they throw errors) that template::element::set_properties passes on up to template::form::set_values.

The part I haven't figured out yet is why a call to template::element::set_properties throws the error and shows up in my adp output. But a call to template::form::set_values with the same basic parameters, does not throw the error, I can't see where it catches it... but seems that it just returns without setting any other values in my FORM.

Besides my obvious desire to get this working for me, my question in the related thread still remains unanswered... How do we get little code +/or documentation fixes for things like this into the code distribution so that other newbie OACS users won't get unexpected errors/results from proc calls? ;)

Collapse
Posted by Jade Rubick on
I'd suggest posting it as a bug, with a suggested fix if you can. I just posted a documentation bug last week, and someone actually put it in (I was surprised and happy :)
Collapse
Posted by tammy m on

Good advice Jade:)

I figured out this was basically the problem:
template::form::set_values does not set values in the FORM from the array reference passed to it. This is because the upvar is not referencing the correct level. Also, once this is fixed and values are being set from the array to the FORM, if a value exists in the array that is not in the FORM, an undocumented/unexpected error is thrown.

And submitted a bug report.