adding cancel button to auth form

69 views
Skip to first unread message

Sebastian E. Ovide

unread,
Jul 23, 2009, 5:43:00 PM7/23/09
to web2py-users
Hi All,

I need to add a Cancel botton the some auth form (change password and retrieve password). Clicking on the cancel button the form should redirect to a given URL.

Do I need to create a new form in my controller ?

Is there any easier way to do it ? (for example altering the form created by auth)

def retrieve_password():
  form=auth.retrieve_password()
  # ADD CANCEL BUTTON HERE THAT REDIRECTS TO SOME URL  IN SOME WAY
  #...
  return dict(form=form)

thanks

--

Sebastian E. Ovide


Sent from Dublin, Ireland

mdipierro

unread,
Jul 23, 2009, 8:31:57 PM7/23/09
to web2py-users
something like this?

form.append(BUTTON('click me',_onclick='document.location="%s"' % URL
(f='index')))

You may want to play with

form[0].append(...)
form[0][0].append(...)
form[0].insert(-1,....)
etc.

depending on where you want to insert the button.


On Jul 23, 4:43 pm, "Sebastian E. Ovide" <sebastianov...@gmail.com>
wrote:

Randell Benavidez

unread,
Jul 25, 2009, 2:47:19 AM7/25/09
to web2py-users
Doing this on gluon.tools.Auth.retrieve_password does nothing (no
additional buttons is added). How can I modify the form in my own
controller which only has def retrieve_password(): return dict
(form=auth.retrieve_password())?

mdipierro

unread,
Jul 25, 2009, 3:18:31 AM7/25/09
to web2py-users
You can use a custom view

{{=form.custom.begin}}
{{=form.custom.widget.email}}
<button> </button>
{{=form.custom.end}}

On Jul 25, 1:47 am, Randell Benavidez

Randell

unread,
Jul 25, 2009, 3:36:15 AM7/25/09
to web...@googlegroups.com
On Sat, Jul 25, 2009 at 3:18 PM, mdipierro <mdip...@cs.depaul.edu> wrote:

You can use a custom view

{{=form.custom.begin}}
{{=form.custom.widget.email}}
<button> </button>
{{=form.custom.end}}

But this method will create a new form next to the retrieve password form.  How can I do it in such a way that the new Cancel button is beside the Submit button?

Randell

unread,
Jul 25, 2009, 3:47:38 AM7/25/09
to web...@googlegroups.com
Nevermind.  I was able to do it by adding

form[0][-1][1].append(INPUT(_type='button',_value='Cancel',_onclick="window.location='%s';"%URL(r=request,f='index')))

which I found here: http://groups.google.com/group/web2py/browse_thread/thread/2bb488401573d19f although I do not know what those indeces in the form are.

--
http://randell.ph/

mdipierro

unread,
Jul 25, 2009, 3:50:26 AM7/25/09
to web2py-users


On Jul 25, 2:36 am, Randell <josephrandell.benavi...@gmail.com> wrote:
> On Sat, Jul 25, 2009 at 3:18 PM, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > You can use a custom view
>
> > {{=form.custom.begin}}
> > {{=form.custom.widget.email}}
> > <button> </button>
> > {{=form.custom.end}}
>
> But this method will create a new form next to the retrieve password form.
> How can I do it in such a way that the new Cancel button is beside the
> Submit button?


Instead of {{=form}} you can use

{{=form.custom.begin}}
{{=form.custom.widget.email}}
{{=form.custom.submit}}<button>yourbutton</button>
{{=form.custom.end}}

(this replaces {{=form}}!)
You should be place the submit and yourbutton where you like.

Anyway, the I am sure the form...append should have worked. Parhaps I
got the wrong [] index.

Randell

unread,
Jul 25, 2009, 3:54:24 AM7/25/09
to web...@googlegroups.com
On Sat, Jul 25, 2009 at 3:50 PM, mdipierro <mdip...@cs.depaul.edu> wrote:



On Jul 25, 2:36 am, Randell <josephrandell.benavi...@gmail.com> wrote:
> On Sat, Jul 25, 2009 at 3:18 PM, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > You can use a custom view
>
> > {{=form.custom.begin}}
> > {{=form.custom.widget.email}}
> > <button> </button>
> > {{=form.custom.end}}
>
> But this method will create a new form next to the retrieve password form.
> How can I do it in such a way that the new Cancel button is beside the
> Submit button?


Instead of {{=form}} you can use

{{=form.custom.begin}}
{{=form.custom.widget.email}}
{{=form.custom.submit}}<button>yourbutton</button>
{{=form.custom.end}}

Ah, right. This works as well.

Thanks!
Reply all
Reply to author
Forward
0 new messages