Thanks much for your explanation.

Christopher Arndt wrote:
> Suren schrieb:
> > If I have multiple buttons on a form, how does the controller which
> > button has been clicked? I can send all submits to one controller
> > method but how to determine which of those four buttons were clicked?
>
> Just test for the existence of the form variable with the name given to the
> 'name' attribute of the button:
>
> class Controller:
>     @expose(self, **kw):
>          if kw.get('action_kung'):
>              # do action kung
>          elif kw.get('action_foo'):
>            # do action foo
>
> where your form would look like:
>
> <form>
>   ....
>   <input type="submit" name="action_foo" value="Do Kung!">
>   <input type="submit" name="action_foo" value="Do Foo!">
> </form>
>
> The test for the existence of the submit button should really be
>
> kw.get('action_foo') is not None
>
> but since form variables will be always strings, unless you mangle them with
> validators, there is no danger that a 0 (zero) integer value will be
> interpreted as False.
>
>
> Explanation:
>
> You test for the name rather for the value of the submit button, because 
> submit
> buttons display their value as the button label, which will probably change in
> your application according to i18n, so you can't test for it in your 
> controller.
>
> Normally, one should be able to use <button type="submit"> elements instead,
> since these can contain any element, but stupid IE will always submit values
> for *all* <button> elements in a form, regardless of which one you click!
>
> You can test this with this simple form:
>
> <form>
> <input type="text" name="text" size="50">
>
> <button name="nosubmit">
>   This does nothing
> </button>
>
> <button type="submit" name="kung">
>   Do Kung!
> </button>
> <button type="submit" name="foo">
>   Do Foo!
> </button>
> 
> </form>
> 
> HTH, Chris


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to