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?
> 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?
> 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 Via Bazzanese,69 Casalecchio di Reno(BO) - Tel. 051591054 +------------------------------------------------------------+
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:
> > 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
> Via Bazzanese,69 Casalecchio di Reno(BO) - Tel. 051591054
> +------------------------------------------------------------+
> 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
-- +------------------------------------------------------------+ Glauco Uri glauco(at)sferacarta.com
Sfera Carta SoftwareŽ info(at)sferacarta.com Via Bazzanese,69 Casalecchio di Reno(BO) - Tel. 051591054 +------------------------------------------------------------+
> 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
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.
On Mar 25, 1:17 pm, "Diez B. Roggisch" <de...@web.de> 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
> 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']
> 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']
Obviously, replace "text" with whatever name your input-field has.
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.
On Mar 26, 5:31 pm, "Diez B. Roggisch" <de...@web.de> wrote:
> > 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']