[Zope] redirection problem

J Cameron Cooper zope-l at jcameroncooper.com
Wed Sep 29 20:19:19 EDT 2004


Larry McDonnell wrote:
> J Cameron Cooper wrote:
> 
>> Larry McDonnell wrote:
>>
>>> I have run into a wall. I am trying to use a pull down menu to 
>>> redirect the form to another page.
>>>
>>> <select name="form_action_type" size="1">
>>>
>>> <dtml-in lookup_action_query sort=school_name>
>>>   <OPTION VALUE="<dtml-var action_file_location>">
>>>   <dtml-var school_name> <dtml-var sport_type>
>>>   </OPTION>
>>> </dtml-in>
>>> </SELECT>
>>>
>>> action_file_location hold the path to where I am trying to get to. I 
>>> tried this
>>> <form method="post" action=<dtml-var expr="form_action_type">>
>>>
>>> But I get a key error. I am trying to do this on the same form.Can I 
>>> do this? Can some point me in the right direction.
>>
>>
>>
>> How is DTML to know what the selected value of the HTML widget is? 
>> Remember that the choice is client side and the rendering is all 
>> server side. If it doesn't exist in the namespace upon rendering, a 
>> name will never be found, thus your key error.
>>
>> The object to which this form is submitted will have 
>> 'form_action_type' in the REQUEST, however.
>>
>> You have two options:
>>
>> 1. use Javascript to change the form's action value upon change in the 
>> widget.
>>
>> 2. create a Python script and submit the form to that. The script will 
>> look up the value in the REQUEST and do a redirect. This will look 
>> something like::
>>
>>   ## parameters=form_action_type
>>
>>   context.REQUEST.RESPONSE.redirect(form_action_type)
>>
>>
>> I like #2 because it doesn't rely on browser capabilities. Your other 
>> option is to restructure your UI: make it a list of links and the 
>> problem goes away. May or may not be feasible.
>>
>>             --jcc
>>
> Hi,
> 
> I can get the standalone python script to work but when I put this in 
> zope I get two different errors:
> 
> I get a page does not diplay error if  I do this:
> 
> <dtml-in lookup_action_query sort=school_name>
>   <OPTION VALUE="<dtml-var action_file_location>">
>   <dtml-var school_name> <dtml-var sport_type>
>   </OPTION>
> </dtml-in>
> </SELECT>
>   <dtml-call "action_type(REQUEST)">
> 
> I get a name error
> <select name="form_action_type" size="1">
> 
> <dtml-in lookup_action_query sort=school_name>
>   <OPTION VALUE="<dtml-var action_file_location>">
>   <dtml-var school_name> <dtml-var sport_type>
> 
>   </OPTION>
> </dtml-in>
> </SELECT>
> 
>   <dtml-call "action_type(action_file_location)">
> 
> I am still weak on my python/zope coding. Any help would be great.

You must become one with HTTP.

Only upon submitting your form does the value in 'form_action_type' 
become known to Zope.

I'm assuming your redirecting script is called 'action_type'. You must 
submit the form to that script. And that means that you make the form's 
action to be the location of the script.

This is how you call the script with the REQUEST; no need to do a 
dtml-call. That would only work if you were dealing in a REQUEST in 
which Zope already had knowledge of your value.

It'll look something like::

  <form method="post" action="form_action_type">
     <select name="form_action_type" size="1">

     <dtml-in lookup_action_query sort=school_name>
       <OPTION VALUE="<dtml-var action_file_location>">
         <dtml-var school_name> <dtml-var sport_type>
      </OPTION>
     </dtml-in>
     </select>
  </form>

			--jcc


More information about the Zope mailing list