Forum OpenACS Development: passing a list from form to form

Collapse
Posted by Janine Ohmer on
I'm in uncharted (for me) territory again... this time it's a form that calls the form handler directly.  Bulk mail in dotLRN, to be exact.

I'm inserting a page that will allow the person sending the bulk mail to optionally choose which group members they want it to go to.  So where the flow used to go spam (create form) -> spam (validate form and load spam-2) -> spam (send message),  it now goes spam-recipients (build list of user ids) -> spam (create form) -> etc.

I have no problem passing my list of user ids from spam-recipient to spam, but it's not surviving the round trip through the form.  The entry in ad_page_contract in spam.tcl looks like this:

    {recipients:integer,multiple,notnull}

when the form is created in spam.tcl it contains this:

element create spam_message recipients \
    -label Recipients \
    -datatype integer \
    -widget hidden \
    -value $recipients

Which looks like this:

<input type="hidden" name="recipients" value="475 287" />

in the browser.

The problem is that when I come back into spam.tcl, this no longer looks like a list of integers and it gets rejected by ad_page_contract with

"recipients is not an integer"

I consulted the documentation, which seemed to imply that I should be using -values instead of -value in my form element.  I tried various variations on that:
-values $recipients
-values [list $recipients]
-values [split $recipients]

But in all cases I ended up with

<input type="hidden" name="recipients" />

Not exactly what was wanted.

Suggestions? Thanks in advance!

Collapse
Posted by Jun Yamog on
Hi Janine,

I charted on this waters and so did Jeff Lu.  Sadly I think if no one implements a hidden widget that accepts -values and renders them in many hidden widgets.  I guess you will have to change your course.  Unless I missed something big, from what I know you will have to code additional code in acs templating.  So hidden with multiple values will render in multiple hiddens.

I thought we where just doing things wrongly and did not get much advice from the forum.  I guess there are 3 of us doing something similar.  Maybe its worth it to have multiple hidden.  Anyway can't volunteer any code, but I hope someone will.  It should help atleast 3 poor souls :)

Collapse
Posted by Darren Ferguson on
This is an ugly work around but you could do the following.

set a [list 245 278]

set a [string map " " "-" $a]

then set a as the value in the hidden field.

Then in your spam.tcl for processing the form you can do transform the numbers back using the string map function
Not sure how good the suggestion is but it should work

Darren

Collapse
Posted by Janine Ohmer on
I ended up doing something similar to what Darren suggests.

spam.tcl now takes both recipients and recipients_str as arguments.  The former is a multiple and the latter just a string.  Both are optional, and the validation block is used to make sure that one of them is set.  If the string is set then it is split into a list, recipients is set properly, and off we go.

Kind of nasty, but I think it's as clean as I can make it under the circumstances.  Glad to hear I wasn't overlooking something obvious!

Collapse
Posted by Jade Rubick on
If anybody wants to add this functionality in, the bug is here:

https://openacs.org/bugtracker/openacs/bug?bug%5fnumber=731