I have a form with two submit buttons. Rather than call two different methods as in <form action="" method="post"> ... <input type="submit" name="some_func:method" value="Button 1"> <input type="submit" name="some_other_func:method" value="Button 2"> </form> I would like each button to call the same function, but with a different value for a variable. Something like: <form action="" method="post"> ... <input type="hidden" name="somevar" value="someval"> <input type="submit" name="some_func:method" value="Button 1"> <input type="hidden" name="somevar" value="someotherval"> <input type="submit" name="some_func:method" value="Button 2"> </form> But this doesn't work. Any suggestions? Thanks, John Hunter
On Thursday 09 May 2002 3:22 am, John Hunter wrote:
I have a form with two submit buttons. Rather than call two different methods as in
<form action="" method="post"> ... <input type="submit" name="some_func:method" value="Button 1"> <input type="submit" name="some_other_func:method" value="Button 2"> </form>
I would like each button to call the same function, but with a different value for a variable. Something like:
<form action="" method="post"> ... <input type="hidden" name="somevar" value="someval"> <input type="submit" name="some_func:method" value="Button 1"> <input type="hidden" name="somevar" value="someotherval"> <input type="submit" name="some_func:method" value="Button 2"> </form>
But this doesn't work.
Any suggestions? Thanks, John Hunter
I do this with JavaScript. Use a hidden input tag to store the variable, and call a function (with your parameters) on the click event of your button which sets the parameters in the request and submits the form. It's not the greatest solution, but it works. I need to use JavaScript anyway since my buttons aren't in the same frame as the form. Harry
Hello Harry, Thursday, May 9, 2002, 11:55:41 AM, you wrote: HW> On Thursday 09 May 2002 3:22 am, John Hunter wrote:
I have a form with two submit buttons. Rather than call two different methods as in
<form action="" method="post"> ... <input type="submit" name="some_func:method" value="Button 1"> <input type="submit" name="some_other_func:method" value="Button 2"> </form>
I would like each button to call the same function, but with a different value for a variable. Something like:
<form action="" method="post"> ... <input type="hidden" name="somevar" value="someval"> <input type="submit" name="some_func:method" value="Button 1"> <input type="hidden" name="somevar" value="someotherval"> <input type="submit" name="some_func:method" value="Button 2"> </form>
But this doesn't work.
the submit buttons count as form-fields as well , so you don't need the hidden form-fields at all : <form action="some_func" method="post"> <input type="submit" name="somevar" value="someval" /> <input type="submit" name="somevar" value="someotherval" /> </form> -- Geir Bækholt web-developer geirh@funcom.com funcom oslo | webdev-team
On Thursday 09 May 2002 11:27 am, Geir Bækholt wrote:
the submit buttons count as form-fields as well , so you don't need the hidden form-fields at all : <form action="some_func" method="post">
<input type="submit" name="somevar" value="someval" /> <input type="submit" name="somevar" value="someotherval" /> </form>
Ah, good point :) I am just using the hidden form fields because I have my buttons in a different frame (and thus in a different form). Looks like John's problem is easier to solve than I though :) Harry
"Geir" == Geir Bækholt <geirh@funcom.com> writes:
Geir> <input type="submit" name="somevar" value="someval" /> Geir> <input type="submit" name="somevar" value="someotherval" /> Geir> </form> Neat idea. At first I balked because the value is also the text for the variable, and I wanted one the button's to say something like 'Update Form' with somevar=0 'Add event' with somevar=1 But I realize that I can process these in the add function, with if somevar=='Update Form': somevar=0 elif somevar=='Add Event': somevar=1 else: raise 'Did you change the value of your add form buttons and forget to change your add function again?' Not the cleanest design, because if you want to change the text of the button you have to remember to change your add form, but it should work. Thanks, John Hunter
John Hunter wrote:
"Geir" == Geir Bækholt <geirh@funcom.com> writes:
Geir> <input type="submit" name="somevar" value="someval" /> Geir> <input type="submit" name="somevar" value="someotherval" /> Geir> </form>
Could this be used instead? <input name="yourEditMethod:method" type="submit" value="Update Form" /> <input name="yourAddMethod:method" type="submit" value="Add Event" /> cheers, Chris
On Thu, May 09, 2002 at 02:16:44PM +0100, Chris Withers wrote:
John Hunter wrote:
> "Geir" == Geir Bækholt <geirh@funcom.com> writes:
Geir> <input type="submit" name="somevar" value="someval" /> Geir> <input type="submit" name="somevar" value="someotherval" /> Geir> </form>
Could this be used instead?
<input name="yourEditMethod:method" type="submit" value="Update Form" /> <input name="yourAddMethod:method" type="submit" value="Add Event" />
I've done something similar (?) in the past: <input name="foo" type="submit" value="Foo Text" /> <input name="bar" type="submit" value="bar Text" /> ... and then in the (single) script handling form submissions, I just tested for existence of foo and bar. I forget exactly the code I used to do that, but it was pretty easy. In your version, where are yourEditMethod and yourAddMethod defined? Are they acquired from somewhere? I smell a better solution than mine, but I don't quite follow how this works... -- "Welcome to Muppet Labs, where the future is made - today!"
Paul Winkler wrote:
In your version, where are yourEditMethod and yourAddMethod defined? Are they acquired from somewhere? I smell a better solution than mine, but I don't quite follow how this works...
This is ZPublisher being useful and it's actually documented in the dead tree version of the Zope book. If the action of the form is an object, say: <form action="http://server.com/an_object"> Then the stuff I posted will result in the following method call: an_object.yourEditMethod(REQUEST) ...of course, the parameters are adjusted by ZPublisher too to match that of your method :-) hope this makes sense, Chris
on or about, Thursday, May 09, 2002, we have reason to believe that John Hunter wrote something along the lines of : [snip] JH> But I realize that I can process these in the add function, with JH> if somevar=='Update Form': JH> somevar=0 JH> elif somevar=='Add Event': JH> somevar=1 JH> else: JH> raise 'Did you change the value of your add form buttons and forget to change your add function again?' JH> Not the cleanest design, because if you want to change the text of the JH> button you have to remember to change your add form, but it should JH> work. - This design is slightly flawed , because many people , including myself , often submit forms by pressing [enter]. In this case , neither of the values from the submitbuttins are sent, and your application will raise 'Did you change ..... you might want to let the else:clause point to one of your options , if one can be considered a default.. :-) -- Geir Bækholt web-developer geirh@funcom.com funcom oslo | webdev-team
Please don't do that. It's a maintenance nightmare, an internationalization nightmare, and an ugly design to boot. Use the :method idiom, it's designed to that. Florent John Hunter <jdhunter@ace.bsd.uchicago.edu> wrote:
Geir> <input type="submit" name="somevar" value="someval" /> Geir> <input type="submit" name="somevar" value="someotherval" /> Geir> </form>
Neat idea. At first I balked because the value is also the text for the variable, and I wanted one the button's to say something like
'Update Form' with somevar=0 'Add event' with somevar=1
But I realize that I can process these in the add function, with
if somevar=='Update Form': somevar=0 elif somevar=='Add Event': somevar=1 else: raise 'Did you change the value of your add form buttons and forget to change your add function again?'
Not the cleanest design, because if you want to change the text of the button you have to remember to change your add form, but it should work.
-- Florent Guillaume, Nuxeo (Paris, France) +33 1 40 33 79 87 http://nuxeo.com mailto:fg@nuxeo.com
"Florent" == Florent Guillaume <fg@nuxeo.com> writes:
Florent> Please don't do that. It's a maintenance nightmare, an Florent> internationalization nightmare, and an ugly design to Florent> boot. Use the :method idiom, it's designed to that. Right, but unless I'm missing something, the method idiom is used to call different methods. If you saw the original post, I want to call the same method with different values for a given variable. Can you do this with :method? Thanks, John Hunter
Ok there are basically two ways. The one I use in most cases: <form action="some_func"> ... <input type="submit" name="submit1" value="Button 1"> <input type="submit" name="submit2" value="Button 2"> </form> and check which of "submit1" or "submit2" variables exist to distinguish the buttons. Or use :method with two different methods: some_func.py ##parameters=..., isbutton2=0 ... processing here ... some_other_func.py: ##parameters=... context.some_func(..., isbutton2=1) Florent John Hunter <jdhunter@ace.bsd.uchicago.edu> wrote:
"Florent" == Florent Guillaume <fg@nuxeo.com> writes:
Florent> Please don't do that. It's a maintenance nightmare, an Florent> internationalization nightmare, and an ugly design to Florent> boot. Use the :method idiom, it's designed to that.
Right, but unless I'm missing something, the method idiom is used to call different methods. If you saw the original post, I want to call the same method with different values for a given variable. Can you do this with :method?
Thanks, John Hunter
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
-- Florent Guillaume, Nuxeo (Paris, France) +33 1 40 33 79 87 http://nuxeo.com mailto:fg@nuxeo.com
participants (7)
-
Chris Withers -
Florent Guillaume -
Geir Bækholt -
Geir B�kholt -
Harry Wilkinson -
John Hunter -
Paul Winkler