[Zope3-Users] keeping GET data in a formlib based form
Maciej Wisniowski
maciej.wisniowski at coig.katowice.pl
Wed Mar 14 05:39:15 EDT 2007
> I need a way to keep 'myarg' information in my form for subsequent
> calls. Ideally I would like some mechanism that ends writing an <input
> type="hidden" id="myarg" value="23"/> tag in the html because that way
> my code:
>
> def update(self):
> [..]
> data = self.request['myarg']
> [..]
>
> will still work, right?
>
> I have thought about extending the formlib template to just do that or
> maybe adding a form.Field to my form with a special Widget associated to
> it. No idea of what's the best aproach.
>
> Anyone has pointer for this?
Maybe the simplest solution is to use session for storing this data,
eg.:
in update you check if there is 'myarg' in request, and if so then
put this into session. If there is no 'myarg' in request
you get this from session.
If you want this passed via POST/GET then you may try with
hidden() method of widgets, or write own widget that
renders as a hidden input, like:
class EntryWidget(SimpleInputWidget):
def _toFieldValue(self, input):
return unicode(input)
def __call__(self):
return self.hidden()
and assign this widget to field that will represent 'myarg':
self.form_fields['myarg'].custom_widget=EntryWidget
You will possibly have to change the line:
data = self.request['myarg']
because your input will have form prefix.
I'm not sure, but you may have some issues with this solution
when doing resetForm etc.
--
Maciej Wisniowski
More information about the Zope3-users
mailing list