[Zope] Re: how to get the name of the element from the formulator in zpt

Sam Peterson skpeterson at ucdavis.edu
Fri Aug 8 12:27:43 EDT 2003


---Exteam said on Sunday, Jul 27 2003:
> hi 
> i need to get the name of the element from the
> formulator in zpt. i have done some thing like this,
> 
> <input type="text" 
> tal:attributes="value python:'%s' %
> record['test_table_name1'];
> name python:form.test_table_name.get_value('title')">
> 
> test_table_name1 is  my column name in the db table &
> test_table_name is my formulator element in the
> formulator . Title of test_table_name is "test table
> name" in the formulator.
> 
> this displays a text box with the value coming from db
> using a py script & name as title of the element , 
> 
> <input type=text 
>         name="test table name" value=abc>
> abc comes from db using py.
> 
> but how do i get the name of the element as name
> attribute in the input type=text ie, how to display 
> <input type=text 
>         name="field_test_table_name" value=abc>

Well, it's best to render fields from a formulator form using the
element's member function .render().  You can pass a string value to
it to set that form element's value attribute, if applicable, or
recreate what the user submitted with the form, by using
.render_from_request(request).

However, if you're looking to get the Id of the formulator element:

field.getId()

and if you need the name of the field to have the 'field_' prefix, use
a python expression and concatenate to the Id.

'field_' + field.getId()

HTH.

-- 
Sam Peterson
skpeterson at ucdavis.edu
530-752-9332
Hart Interdisciplinary Programs, University of California, Davis



More information about the Zope mailing list