Forum OpenACS Q&A: template::form::set_property needed!

Collapse
Posted by tammy m on

Hi,

I'm trying to set the action for my form to pass a parameter like so template::form::create $form_name -method POST -property "action {task-new?story_id=$story_id}" Of course there is no -property and -html does not work for this.

But I do see this code in template::form::render

  # set the form to point back to itself if action is not specified
  if { ! [info exists properties(action)] } {
    set properties(action) [ns_conn url]
  }

It looks like the intention is to allow action to be specified. So the obvious question is what the is the recommended way to set a form parameter (like action!)? I'm not using ad_form btw, I have reasons for that so please don't recommend that;)

tia

Collapse
Posted by Dave Bauer on
I believe you just pass it in as -action "task-new?story_id=$story_id" to template::form create

although I still recommend you look into using self-submit forms which are supported by the form builder as well as ad_form.

I am really confused as to why you would pass in URL variables with a form. More traditionally you would add a hidden form element.

Collapse
Posted by tammy m on
Well

Here's the thing. I request my page that displays the form by passing an id to it like task-new?story_id=8877 the first time I call it. So I use ad_page_contract to enforce that the story_id is required (it really is as I can't create a task without a parent story).

So then when the form is resubmitted, the story_id being required by ad_page_contract blows up. Thus I need to call the page the same way I called it when it first showed the form.

So I can create a hidden and put it in the form and get it back out etc. But then I can't really use ad_page_contract to enforce story_id being passed the first time my form display page is called. But I do think I can't do a GET and POST (meaning I can't pass parameters in the URL and via a form) at the same time.

Collapse
Posted by Dave Bauer on
Aha.

Ok here is another option. Store the requesting URL in the form as a hidden element. Then after processing the form, ad_returnredirect to the return_url.

Like this:

set return_url [ad_return_url]

Then add return_url as a hidden form element.

Collapse
Posted by tammy m on
Aah,

Maybe I shoulda posted the problem before I posted the half thought out solution;(

thanks Dave.