Reset for fields

1 view
Skip to first unread message

GSP

unread,
Mar 24, 2008, 4:26:17 PM3/24/08
to TurboGears
This is likely a basic question. When submitting a form, how does one
specify certain fields to be reset upon redirection to the original
page. For example, clearing password and user name fields in a
registration screen?

thanks!

GSP

unread,
Mar 25, 2008, 10:26:33 AM3/25/08
to TurboGears
Has anyone encountered this issue?

Glauco

unread,
Mar 25, 2008, 10:40:48 AM3/25/08
to turbo...@googlegroups.com
GSP ha scritto:

is a strange issue...

but anyway your web form is inside TG a simple dict() so you can do
anywere before rendering of the page:


for fi in ['field1','field2']
data[ fi ] = None
turbogears.redirect( bla bla bla, **data )

Have i understood right?


Gla

--
+------------------------------------------------------------+
Glauco Uri
glauco(at)sferacarta.com

Sfera Carta SoftwareŽ info(at)sferacarta.com
Via Bazzanese,69 Casalecchio di Reno(BO) - Tel. 051591054
+------------------------------------------------------------+


GSP

unread,
Mar 25, 2008, 12:13:51 PM3/25/08
to TurboGears
I am thinking along the lines of when validation is performed and for
example a password field fails validation.It is preferable to return
to the original form with the password fields cleared. However, it is
not evident to me where and when this could be performed since
validation and redirection is performed deep within a layer of magic.
I am sure there must be an easy way to do this. Coming from a Java
Struts background I am familiar with the reset method of a form to
perform this action, however, it is not apparent how this is done
using TG forms.
On Mar 25, 10:40 am, Glauco <gla...@sferacarta.com> wrote:
> GSP ha scritto:
>
> > This is likely a basic question. When submitting a form, how does one
> > specify certain fields to be reset upon redirection to the original
> > page. For example, clearing password and user name fields in a
> > registration screen?
>
> > thanks!
>
> is a strange issue...
>
> but anyway your web form is inside TG a simple dict() so you can do
> anywere before rendering of the page:
>
> for fi in ['field1','field2']
> data[ fi ] = None
> turbogears.redirect( bla bla bla, **data )
>
> Have i understood right?
>
> Gla
>
> --
> +------------------------------------------------------------+
> Glauco Uri
> glauco(at)sferacarta.com
>
> Sfera Carta Software® info(at)sferacarta.com

Glauco

unread,
Mar 25, 2008, 12:44:13 PM3/25/08
to turbo...@googlegroups.com
GSP ha scritto:

> I am thinking along the lines of when validation is performed and for
> example a password field fails validation.It is preferable to return
> to the original form with the password fields cleared. However, it is
> not evident to me where and when this could be performed since
> validation and redirection is performed deep within a layer of magic.
> I am sure there must be an easy way to do this. Coming from a Java
> Struts background I am familiar with the reset method of a form to
> perform this action, however, it is not apparent how this is done
> using TG forms.
>

Ahh ok , probably i've understood now :-)


def your_controller(self,tg_errors=None, **data):
if tg_errors:
# I want to RESET hardly these fields in all case of error
data['my_field1_to_reset'] = None
data['my_field2_to_reset'] = None

Glauco

Diez B. Roggisch

unread,
Mar 25, 2008, 1:17:45 PM3/25/08
to turbo...@googlegroups.com, GSP
On Tuesday 25 March 2008 17:13:51 GSP wrote:
> I am thinking along the lines of when validation is performed and for
> example a password field fails validation.It is preferable to return
> to the original form with the password fields cleared. However, it is
> not evident to me where and when this could be performed since
> validation and redirection is performed deep within a layer of magic.
> I am sure there must be an easy way to do this. Coming from a Java
> Struts background I am familiar with the reset method of a form to
> perform this action, however, it is not apparent how this is done
> using TG forms.

Besides that I never understood the reason a password-field is cleared in such
cases & find it an annoyance (it is *NOT* security, just a false sense of),
you have two options here:

- use Javascript (easy, but not so nice)

- you need to clear the cherrypy.request parameters for the passsword-fields.
I'm not totally sure out of my head how to do so - but either

del cherrypy.request.password
cherrypy.request.password = None

or such should do the trick.

Diez

GSP

unread,
Mar 25, 2008, 7:13:11 PM3/25/08
to TurboGears
I appreciate everyones response. Unfortutely, I tried each suggestion
but the fields did not reset as expected.
I did try instantiating the form in the controller method and this
achieves the goal of resetting the fields, however, data used to
identify if a field is in
error is discarded. Obviously, this is not a good solution. I wonder
if any of the project developers could offer a hint. Surely this is
not an uncommon use case.

Diez B. Roggisch

unread,
Mar 26, 2008, 5:31:48 PM3/26/08
to turbo...@googlegroups.com
GSP schrieb:

> I appreciate everyones response. Unfortutely, I tried each suggestion
> but the fields did not reset as expected.

You certainly didn't try every suggestion - Javascript would have helped.

> I did try instantiating the form in the controller method and this
> achieves the goal of resetting the fields, however, data used to
> identify if a field is in
> error is discarded. Obviously, this is not a good solution. I wonder
> if any of the project developers could offer a hint. Surely this is
> not an uncommon use case.


Matter of factly I am one of the developers. But I have to admit that
this is one of the darker black magic corners of turbogears that is hard
to grasp. I had to dig deep to find what's happening, and I'm actually
not sure how everything works - but I managed to solve the issue.

My basic suggestion of manipulating the request was right - but not the
actual key/name used.

Try this:

if hasattr(request, "input_values") and 'text' in request.input_values:
del request.input_values['text']


Diez

Diez B. Roggisch

unread,
Mar 26, 2008, 5:48:51 PM3/26/08
to turbo...@googlegroups.com
Diez B. Roggisch schrieb:

Obviously, replace "text" with whatever name your input-field has.

Diez

GSP

unread,
Mar 26, 2008, 6:27:08 PM3/26/08
to TurboGears
Ah yes of course, I should have been more specific and referred to the
server side solutions as a server side solution
was my primary goal. I suppose this is a case where the framework
makes the common case uncommonly difficult.
I can't help but think some type of form reset method would be a
useful extension to the existing form handling mechanism.
Hopefully, this simple goal could be achieved within the context of
whatever magic is happening behind the scenes.
I would be interested to hear opinions on this.
Reply all
Reply to author
Forward
0 new messages