Here's an even better solution :) if 'MSIE' in request.env.http_user_agent: redirect('http:/getfirefox.com/')
But seriously, I see your point. It's a bit of a catch 22 as you are either coding around browser quirks or relying on javascript. On Feb 27, 8:42 pm, Jonathan Lundell <jlund...@pobox.com> wrote: > On Feb 27, 2010, at 6:25 PM, mr.freeze wrote: > > > > > I disagree, the behavior seems controllable to me and I use it often. > > In IE, a submit done via the enter key on a text input doesn't send > > any of the <input type='submit' values back. On firefox, a submit > > done with the enter key will send the first submit value. Just make > > your default submit the first one and you can determine what to do > > with your form. Here's a revised example: > > > form = FORM('blah blah', > > INPUT(_type='text', _value='test',_name="test"), > > INPUT(_type='submit', _value='Reset',_name="reset"), > > INPUT(_type='submit', _value='Apply',_name="apply"), > > > INPUT(_type='submit', _value='Reset > > all',_name="resetall")) > > if request.vars.apply: > > pass #clicked or enter was hit on FF > > elif request.vars.reset: > > pass #clicked > > elif request.vars.resetall: > > pass #clicked > > else: > > pass #enter was hit on IE, do apply > > > Maybe I'm missing something? > > The main problem with that approach is that it relies on undocumented > reverse-engineered behavior of IE. Now, that's something we're forced to do > from time to time, but unless you're averse to using JavaScript, there are > solutions (like Iceberg's and mine) that avoid the IE issue altogether. > > Also, in my case, I don't actually need a submit button (vs a button button) > for my cancel function, since I need to catch the cancel before calling > accepts()--I don't want to invoke the validators on a cancel. > > But if you really need multiple submits, and you're willing to use > JavaScript, Iceberg's solution is slick. > > Some interesting research on the IE > problem:http://muffinresearch.co.uk/archives/2005/12/08/fun-with-multiple-sub... > > > > > On Feb 27, 8:06 pm, Iceberg <iceb...@21cn.com> wrote: > >> I think Jonathan have given enough reason of why not. There is > >> another post to discuss the same > >> thing.http://groups.google.com/group/web2py/msg/79c1f847890a6b60 > > >> In short, do resist the temptation of using multiple submit buttons, > >> pal. :) > > >> On Feb28, 9:36am, "mr.freeze" <nat...@freezable.com> wrote: > > >>> Why not just do this?: > > >>> def index(): > >>> form = FORM('blah blah', > >>> INPUT(_type='submit', _value='Apply',_name="apply"), > >>> INPUT(_type='submit', _value='Reset',_name="reset"), > >>> INPUT(_type='submit', _value='Reset > >>> all',_name="resetall")) > >>> if request.vars.apply: > >>> pass #apply was clicked > >>> elif request.vars.reset: > >>> pass #reset was clicked > >>> elif request.vars.resetall: > >>> pass #resetall was clicked > > >>> On Feb 27, 6:30 pm, Jonathan Lundell <jlund...@pobox.com> wrote: > > >>>> On Feb 27, 2010, at 4:03 PM, Thadeus Burgess wrote: > > >>>>> If your running the latest version of web2py, look at > >>>>> controllers/appadmin.py in ccache function. It defines a form with > >>>>> three buttons, (one toc lear ram, one to clear disk, and one to clear > >>>>> both). Click the different submit button executes the appropriate > >>>>> function. > > >>>> A caveat, though: this approach is problematical if the form has a text > >>>> input field and the user submits the form by typing return in an input > >>>> field, rather than clicking a button. > > >>>> The problem as I understand it is that in that case you're not > >>>> guaranteed which button is returned. The culprit (no surprise) is IE. So > >>>> if Tom's form gets submitted by a return in a text field, and the > >>>> browser is IE, he presumably wants to see the Apply button, but might > >>>> see one of the reset buttons instead--not what the user intended. > > >>>> My approach is to use one submit button, and to make the other buttons > >>>> type=button, with an onclick script to reinvoke the same controller with > >>>> a button ID in vars. You'll typically check for that at the beginning of > >>>> the controller. > > >>>> I've been using it for a cancel button, as well as some > >>>> application-specific functions, and it seems to work well. > > >>>>> -Thadeus > > >>>>> On Sat, Feb 27, 2010 at 5:08 PM, Jonathan Lundell <jlund...@pobox.com> > >>>>> wrote: > >>>>>> On Feb 27, 2010, at 3:00 PM, Tiago Almeida wrote: > > >>>>>> Don't know why functions reset, reset_all are not called but they > >>>>>> reference > >>>>>> a "form" variable which is not in scope? Do you have any global "form"? > > >>>>>> The logic below can't work, for lots of reasons. > >>>>>> One is the one Tiago mentions. Another is that input elements do not > >>>>>> have > >>>>>> action attributes; forms do. There are ways to accomplish this kind of > >>>>>> thing; most of them involve JavaScript. > >>>>>> This might be helpful (though it's not the way I'd do > >>>>>> it):http://www.javascript-coder.com/html-form/html-form-submit.phtml > > >>>>>> Regards, > >>>>>> Tiago > >>>>>> -- > > >>>>>> On Sat, Feb 27, 2010 at 10:15 PM, Tomas Pelka <tompe...@gmail.com> > >>>>>> wrote: > > >>>>>>> Hi all, > > >>>>>>> have some troubles with web form which have more than one button. It > >>>>>>> is > >>>>>>> obvious that one button (action connected with button) correspond with > >>>>>>> one function. > > >>>>>>> According manual this should work: > >>>>>>> controler > >>>>>>> --------- > >>>>>>> def index(): > >>>>>>> form = FORM('blah blah', > >>>>>>> INPUT(_type='submit', _value='Apply'), > >>>>>>> INPUT(_type='submit', _value='Reset', _action=URL(r=request, > >>>>>>> f='reset'), > >>>>>>> INPUT(_type='submit', _value='Reset all', > >>>>>>> _action=URL(r=request, > >>>>>>> f='reset_all')) > >>>>>>> if form.accepts(request.vars, session): > >>>>>>> pass > >>>>>>> elif form.errors: > >>>>>>> response.flash = 'Error' > >>>>>>> else: > >>>>>>> pass > >>>>>>> return dict(form=form) > > >>>>>>> def reset(): > >>>>>>> if form.accepts(request.vars, formname=None): > >>>>>>> response.flash = 'Reset' > >>>>>>> elif form.errors: > >>>>>>> response.flash = 'Error' > >>>>>>> else: > >>>>>>> pass > >>>>>>> return dict() > > >>>>>>> def reset_all(): > >>>>>>> if form.accepts(request.vars, formname=None): > >>>>>>> response.flash = 'Resert all' > >>>>>>> elif form.errors: > >>>>>>> response.flash = 'Error' > >>>>>>> else: > >>>>>>> pass > >>>>>>> return dict() > > >>>>>>> But action functions (reset, reset_all) will not call. Am I doing > >>>>>>> anything wrong? > > >>>>>>> Thanks for advice, > >>>>>>> cheers > > >>>>>>> -- > >>>>>>> Tom > > >>>>>>> Key fingerprint = 06C0 23C6 9EB7 0761 9807 65F4 7F6F 7EAB 496B 28AA > > > -- > > You received this message because you are subscribed to the Google Groups > > "web2py-users" group. > > To post to this group, send email to web...@googlegroups.com. > > To unsubscribe from this group, send email to > > web2py+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/web2py?hl=en. > > -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.