[ZPT] Re: Re: [Zope-DB] How to pass values from a form to a page template?

Charlie Clark charlie at egenix.com
Thu Apr 29 08:41:16 EDT 2004


Vaibhav,

it is always best to post to a list. I'm transferring this to zpt though as 
it is not related to databases. You might also want to sign up to a Plone 
list as there may be other ways of doing this.

On 2004-04-29 at 11:30:02 [+0200], you wrote:
>  Dear Charlie,
> 
>              I have made a DTML document storing the name of some books 
>              which i have to post to a Page template
> here is the coding for the DTML Document.
> 
> <html>
> <body bgcolor="#0099CC">
> <h1>Assign Privileges To book</h1>
> <form method=POST action="access2">
>   PLONE BOOK<select size="1" name="attr1">
>   <option value="CAD">CAD</option>
>   <option value="BARC">BARC</option>
>   <option value="ADA">ADA</option>
>   </select>
>   <input type="submit" value="Assign Roles">
>   <input type="reset" value="Reset"></p>
> </form>
> 
> in this DTML Document

Drop DTML and just use PageTemplates.
 
> 1. the options specified by the select tag are some of the roles defined by 
> me.
> 2. access2 is the Page template to which this value is to be passed

This will give you a Zope-Request object which contains the values of the 
form like a dictionary,
ie. request.attr1 or request.form.attr1 will give you the appropriate value.
 
> here is the code for access2
> ----------------------------------------------------------------------------
> -------------------------------------
>  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> 
> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US"
>       lang="en-US"
>       metal:use-macro="here/main_template/macros/master">
> 
> <body>
> <div metal:fill-slot="main">
> <a 
> tal:condition="python:context.portal_membership.getAuthenticatedMember().has
> _role('???')" href="./plonebook">view pdf</a>
>     
> </div>
>        
> </body>
> </html>
> ----------------------------------------------------------------------------
> ------------------------------
> 
> now i want that the link to the book to be displayed by the page template 
> on the basis of value of 'attr1' passed
> to it by the form i.e the python conditional statement which checks for 
> role should decide the role
> based on the value passed to it.

You should do this using a PythonScript but I think you may well need to 
rethink your application. But anyway here's some code

<div metal:fill-slot="main"
tal:define="userRole request/attr1 | nothing">
> <a 
> tal:condition="python:context.portal_membership.getAuthenticatedMember().has
> _role(userRole)" href="./plonebook">view pdf</a>
>     
</div>

If you want to make what the user sees dependent on what role they have then 
you will are best using a PythonScript as if/elif is very clumsy in ZPT 
especially compared to "dispatching" in Python.
 
> Please help me!!!!

Hope I have a bit.

Charlie Clark
-- 
Charlie Clark
eGenix.com

Professional Python Services directly from the Source
 >>> Python/Zope Consulting and Support ...        http://www.egenix.com/
 >>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
 >>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::



More information about the ZPT mailing list