<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>opensoul.org - Handling forms with multiple buttons Comments</title>
  <id>tag:opensoul.org,2008:/2007/7/16/handling-forms-with-multiple-buttons/comments</id>
  <generator version="0.8.0" uri="http://mephistoblog.com">Mephisto Drax</generator>
  <link href="http://opensoul.org/2007/7/16/handling-forms-with-multiple-buttons/comments.xml" rel="self" type="application/atom+xml"/>
  <link href="/2007/7/16/handling-forms-with-multiple-buttons" rel="alternate" type="text/html"/>
  <updated>2007-08-28T02:17:48Z</updated>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Brandon</name>
    </author>
    <id>tag:opensoul.org,2007-07-16:3237:3499</id>
    <published>2007-08-28T02:17:48Z</published>
    <updated>2007-08-28T02:17:48Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/7/16/handling-forms-with-multiple-buttons" rel="alternate" type="text/html"/>
    <title>Comment on 'Handling forms with multiple buttons' by Brandon</title>
<content type="html">&lt;p&gt;Jeremy,&lt;/p&gt;


	&lt;p&gt;My plugin isn&#8217;t doing any special handling for Ajax requests, but I believe Prototype 1.6 has had some improvements in the form serialization code, so it may not be an issue anymore.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Jeremy</name>
    </author>
    <id>tag:opensoul.org,2007-07-16:3237:3494</id>
    <published>2007-08-27T21:41:22Z</published>
    <updated>2007-08-27T21:41:22Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/7/16/handling-forms-with-multiple-buttons" rel="alternate" type="text/html"/>
    <title>Comment on 'Handling forms with multiple buttons' by Jeremy</title>
<content type="html">&lt;p&gt;I&#8217;ve noticed a problem in the past, when doing this kind of thing, where submitting a form via ajax causes it to send all the buttons&#8217; information, so rails doesn&#8217;t know which button was pressed. Does your plugin deal with that?&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Brandon</name>
    </author>
    <id>tag:opensoul.org,2007-07-16:3237:3394</id>
    <published>2007-08-17T15:07:41Z</published>
    <updated>2007-08-17T15:07:41Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/7/16/handling-forms-with-multiple-buttons" rel="alternate" type="text/html"/>
    <title>Comment on 'Handling forms with multiple buttons' by Brandon</title>
<content type="html">&lt;p&gt;David,&lt;/p&gt;


	&lt;p&gt;It does sound like it&#8217;s not installed right. I would just try removing the plugin and installing it again.  Other than that, I don&#8217;t know what to tell you.&lt;/p&gt;


&lt;pre&gt;
script/plugin install http://source.collectiveidea.com/public/rails/plugins/with_action
&lt;/pre&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>David</name>
    </author>
    <id>tag:opensoul.org,2007-07-16:3237:3368</id>
    <published>2007-08-12T22:20:45Z</published>
    <updated>2007-08-12T22:20:45Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/7/16/handling-forms-with-multiple-buttons" rel="alternate" type="text/html"/>
    <title>Comment on 'Handling forms with multiple buttons' by David</title>
<content type="html">&lt;p&gt;Hi, I just installed this plugin but my code throws the following error:&lt;/p&gt;


	&lt;p&gt;undefined method `with_action&#8217; for #&amp;lt;locationscontroller:0x466728c&gt;&lt;/p&gt;


	&lt;p&gt;My guess is that I may not have installed the plugin correctly.  How can I fix this?&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>John Nunemaker</name>
    </author>
    <id>tag:opensoul.org,2007-07-16:3237:3302</id>
    <published>2007-07-31T03:08:19Z</published>
    <updated>2007-07-31T03:08:19Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/7/16/handling-forms-with-multiple-buttons" rel="alternate" type="text/html"/>
    <title>Comment on 'Handling forms with multiple buttons' by John Nunemaker</title>
<content type="html">&lt;p&gt;Just installed this and gave it a try. Super nice work.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Justin</name>
    </author>
    <id>tag:opensoul.org,2007-07-16:3237:3297</id>
    <published>2007-07-29T14:05:02Z</published>
    <updated>2007-07-29T14:05:02Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/7/16/handling-forms-with-multiple-buttons" rel="alternate" type="text/html"/>
    <title>Comment on 'Handling forms with multiple buttons' by Justin</title>
<content type="html">&lt;p&gt;Awesome! I&#8217;m so glad I won&#8217;t be doing this with if/else anymore&#8230;&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Matt Secoske</name>
    </author>
    <id>tag:opensoul.org,2007-07-16:3237:3264</id>
    <published>2007-07-19T12:31:53Z</published>
    <updated>2007-07-19T12:31:53Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/7/16/handling-forms-with-multiple-buttons" rel="alternate" type="text/html"/>
    <title>Comment on 'Handling forms with multiple buttons' by Matt Secoske</title>
<content type="html">&lt;p&gt;Very elegant!&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Sam Nardoni</name>
    </author>
    <id>tag:opensoul.org,2007-07-16:3237:3250</id>
    <published>2007-07-17T12:34:27Z</published>
    <updated>2007-07-17T12:34:27Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/7/16/handling-forms-with-multiple-buttons" rel="alternate" type="text/html"/>
    <title>Comment on 'Handling forms with multiple buttons' by Sam Nardoni</title>
<content type="html">&lt;p&gt;Perfect, just what I&#8217;m looking for.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Brandon</name>
    </author>
    <id>tag:opensoul.org,2007-07-16:3237:3249</id>
    <published>2007-07-17T04:58:44Z</published>
    <updated>2007-07-17T04:58:44Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/7/16/handling-forms-with-multiple-buttons" rel="alternate" type="text/html"/>
    <title>Comment on 'Handling forms with multiple buttons' by Brandon</title>
<content type="html">&lt;p&gt;nkryptic,&lt;/p&gt;


	&lt;p&gt;That&#8217;s a great point. You would hope that &#8220;most&#8221; of the time people would hit cancel before the select any file uploads.&lt;/p&gt;


	&lt;p&gt;Usually I just use a cancel link, but in this situation I decided it looked bad to have 3 buttons and then a cancel link.  But maybe, to get uniformity, I&#8217;ll have to switch to using images for the inputs and then just an image as a link for the cancel button.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>nkryptic</name>
    </author>
    <id>tag:opensoul.org,2007-07-16:3237:3247</id>
    <published>2007-07-17T00:42:38Z</published>
    <updated>2007-07-17T00:42:38Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/7/16/handling-forms-with-multiple-buttons" rel="alternate" type="text/html"/>
    <title>Comment on 'Handling forms with multiple buttons' by nkryptic</title>
<content type="html">&lt;p&gt;One thing I wonder is whether the &#8220;cancel&#8221; button is a bad idea.    If your form contains a file upload field, clicking cancel will upload the file first, before you are redirected, no?&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Chris</name>
    </author>
    <id>tag:opensoul.org,2007-07-16:3237:3246</id>
    <published>2007-07-16T20:18:11Z</published>
    <updated>2007-07-16T20:18:11Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/7/16/handling-forms-with-multiple-buttons" rel="alternate" type="text/html"/>
    <title>Comment on 'Handling forms with multiple buttons' by Chris</title>
<content type="html">&lt;p&gt;This is great stuff.  Definitely bookmarked for future reference. :D&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Matt Aimonetti</name>
    </author>
    <id>tag:opensoul.org,2007-07-16:3237:3245</id>
    <published>2007-07-16T19:42:23Z</published>
    <updated>2007-07-16T19:42:23Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/7/16/handling-forms-with-multiple-buttons" rel="alternate" type="text/html"/>
    <title>Comment on 'Handling forms with multiple buttons' by Matt Aimonetti</title>
<content type="html">&lt;p&gt;Good stuff Brandon. You solution might get a big confusing if you  add too many &lt;em&gt;any&lt;/em&gt; nested blocks but it&#8217;s still a very clean way of dealing with the issue you were facing.&lt;/p&gt;


	&lt;p&gt;Thanks for the plugin, I&#8217;ll keep it handy in case I have to do the same thing soon.&lt;/p&gt;


	&lt;p&gt;Matt&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Eric Anderson</name>
    </author>
    <id>tag:opensoul.org,2007-07-16:3237:3244</id>
    <published>2007-07-16T19:25:05Z</published>
    <updated>2007-07-16T19:25:05Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/7/16/handling-forms-with-multiple-buttons" rel="alternate" type="text/html"/>
    <title>Comment on 'Handling forms with multiple buttons' by Eric Anderson</title>
<content type="html">&lt;p&gt;I can see you point. Not only does my method not work with JavaScript but it actually could do the wrong thing. Perhaps something along the lines of _method then. If you submit buttons look like:&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;
&amp;lt;%=submit_tag 'update', :name =&amp;gt; '_method'%&amp;gt;
&amp;lt;%=submit_tag 'destroy', :name =&amp;gt; '_method'%&amp;gt;
&lt;/code&gt;

That should produce tags that without JavaScript change the action based on what button is pressed (assuming a RESTful setup). Obviously this is fairly limited and flaky but if you did something along those lines so that the value of &#8220;commit&#8221; would determine the action (would require a Rails plugin). You could get the redirects out of your action (keeping them clean) while still not relying on JavaScript.
&lt;/pre&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Brandon</name>
    </author>
    <id>tag:opensoul.org,2007-07-16:3237:3240</id>
    <published>2007-07-16T13:22:50Z</published>
    <updated>2007-07-16T13:22:50Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/7/16/handling-forms-with-multiple-buttons" rel="alternate" type="text/html"/>
    <title>Comment on 'Handling forms with multiple buttons' by Brandon</title>
<content type="html">&lt;p&gt;Eric,&lt;/p&gt;


	&lt;p&gt;That&#8217;s another option.  But one of the ideals that I try to uphold with JavaScript is to make it fail gracefully.  I don&#8217;t care if something doesn&#8217;t work without JavaScript, but it shouldn&#8217;t cause it to behave differently (i.e. Cancel button causes it to save the form).&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Eric Anderson</name>
    </author>
    <id>tag:opensoul.org,2007-07-16:3237:3239</id>
    <published>2007-07-16T12:57:44Z</published>
    <updated>2007-07-16T12:57:44Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/7/16/handling-forms-with-multiple-buttons" rel="alternate" type="text/html"/>
    <title>Comment on 'Handling forms with multiple buttons' by Eric Anderson</title>
<content type="html">&lt;p&gt;I&#8217;ve always handled stuff like this by changing the action with JavaScript. Basically my submit button has an onclick callback that will update the action for the form to the right &lt;span class=&quot;caps&quot;&gt;URL&lt;/span&gt;. I see the tradeoffs as:&lt;/p&gt;


	&lt;p&gt;Your method:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;allows the app to work without Javascript&lt;/li&gt;
		&lt;li&gt;is packaged up in a nice plugin&lt;/li&gt;
		&lt;li&gt;dirties up your actions (for example your &#8220;create&#8221; method above has to care about editing, approving, etc)&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;My method:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;Keeps the server-side actions clean and RESTful&lt;/li&gt;
		&lt;li&gt;Requires Javascript&lt;/li&gt;
		&lt;li&gt;In not packaged up in a nice plugin&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;I can see both methods useful depending on the needs of the situation. Makes me now want to package my method up as a nice plugin. Maybe something like:&lt;/p&gt;


&lt;code&gt;
&lt;pre&gt;
submit_tag 'Approve',
  :action =&amp;gt; approval_path(@article)
&lt;/pre&gt;
&lt;/code&gt;

	&lt;p&gt;which would generate the tag with the necessary JavaScript to update the action.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>Joerg Battermann</name>
    </author>
    <id>tag:opensoul.org,2007-07-16:3237:3238</id>
    <published>2007-07-16T12:49:36Z</published>
    <updated>2007-07-16T12:49:36Z</updated>
    <category term="Code"/>
    <link href="http://opensoul.org/2007/7/16/handling-forms-with-multiple-buttons" rel="alternate" type="text/html"/>
    <title>Comment on 'Handling forms with multiple buttons' by Joerg Battermann</title>
<content type="html">&lt;p&gt;Nice!&lt;/p&gt;</content>  </entry>
</feed>
