Forum OpenACS Development: Passing in two (array) variables to a ad_proc

I'm attempting to pass two variables to a ad_proc and I want to use these variables in a widget selection box.  How do I reference the variables in the select option list.

This is what I have:

in main tcl page:
-----------------
set allowed {gambling hate kids}
set restricted {chat email}
set select_widget [switch $allowed $restricted]]

in tcl ad_proc procedure call:
------------------------------
ad_proc -public switch{
  allowed
  restricted
}{
....
}
{
  set allowed_options ""
  set restricted_options ""

  foreach option $allowed{
    append allowed "<option>$option</option>\n"
  }
  foreach option $restricted{
    append restricted "<option>$option</option>\n"
  }

  set widget {
    ....
      <form>
        <select name="list" multiple="multiple"
          <option>$allowed</option>
        </select>
      </form>
    ....
  }
} return "$widget"
}

This does not work.  It returns a select box with only the value "$allowed".  Can someone please tell me what I am doing wrong as I am a newbie.  Thanks in advance.

Collapse
Posted by russ m on
garry -

in TCL, variables aren't interpolated inside braces, so the $allowed in your set widget statement is taken literally instead of as a variable reference. you need to enclose the content of your set widget statement in "" quotes (which also means you'll need to \" escape all the quotes within the string).

Collapse
Posted by garry g on
Thank you Russell for your quick reply.  I'll give it a go.