<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: How to add a Cancel button to Drupal forms</title>
	<atom:link href="http://www.lacisoft.com/blog/2009/10/05/how-to-add-a-cancel-button-to-drupal-forms/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lacisoft.com/blog/2009/10/05/how-to-add-a-cancel-button-to-drupal-forms/</link>
	<description>SELECT * FROM lacisoft</description>
	<lastBuildDate>Mon, 06 Feb 2012 15:37:11 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: lmeurs</title>
		<link>http://www.lacisoft.com/blog/2009/10/05/how-to-add-a-cancel-button-to-drupal-forms/comment-page-1/#comment-1911</link>
		<dc:creator>lmeurs</dc:creator>
		<pubDate>Mon, 06 Feb 2012 15:37:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.lacisoft.com/blog/?p=288#comment-1911</guid>
		<description>@MadtownLems: add &quot;&#039;#limit_validation_errors&#039; =&gt; array(),&quot; to the cancel button to skip all validation. Ie.:

$form[&#039;cancel&#039;] = array(
  &#039;#type&#039;  =&gt; &#039;submit&#039;,
  &#039;#name&#039;  =&gt; &#039;cancel&#039;,
  &#039;#value&#039;  =&gt; &#039;Cancel&#039;,
  &#039;#limit_validation_errors&#039; =&gt; array(),
);

Cheers

LMeurs, Rotterdam</description>
		<content:encoded><![CDATA[<p>@MadtownLems: add &#8220;&#8216;#limit_validation_errors&#8217; =&gt; array(),&#8221; to the cancel button to skip all validation. Ie.:</p>
<p>$form['cancel'] = array(<br />
  &#8216;#type&#8217;  =&gt; &#8216;submit&#8217;,<br />
  &#8216;#name&#8217;  =&gt; &#8216;cancel&#8217;,<br />
  &#8216;#value&#8217;  =&gt; &#8216;Cancel&#8217;,<br />
  &#8216;#limit_validation_errors&#8217; =&gt; array(),<br />
);</p>
<p>Cheers</p>
<p>LMeurs, Rotterdam</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: strony www</title>
		<link>http://www.lacisoft.com/blog/2009/10/05/how-to-add-a-cancel-button-to-drupal-forms/comment-page-1/#comment-1816</link>
		<dc:creator>strony www</dc:creator>
		<pubDate>Sat, 01 Oct 2011 11:51:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.lacisoft.com/blog/?p=288#comment-1816</guid>
		<description>@rsevero

You can&#039;t find example with disabled validation here
http://devengineering.com/best-practices/drupal/cancellation-required-validation-drupal-6</description>
		<content:encoded><![CDATA[<p>@rsevero</p>
<p>You can&#8217;t find example with disabled validation here<br />
<a href="http://devengineering.com/best-practices/drupal/cancellation-required-validation-drupal-6" rel="nofollow">http://devengineering.com/best-practices/drupal/cancellation-required-validation-drupal-6</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: loony</title>
		<link>http://www.lacisoft.com/blog/2009/10/05/how-to-add-a-cancel-button-to-drupal-forms/comment-page-1/#comment-1815</link>
		<dc:creator>loony</dc:creator>
		<pubDate>Thu, 29 Sep 2011 12:08:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.lacisoft.com/blog/?p=288#comment-1815</guid>
		<description>in D7 u need to do this
 &#039;button&#039;,
        &#039;#attributes&#039; =&gt; array(&#039;onClick&#039; =&gt; &#039;location.replace(\&#039;&#039;. $_SERVER[&#039;HTTP_REFERER&#039;] .&#039;\&#039;); return false;&#039;),
        &#039;#value&#039; =&gt; t(&#039;Cancel&#039;),
    );
?&gt;</description>
		<content:encoded><![CDATA[<p>in D7 u need to do this<br />
 &#8216;button&#8217;,<br />
        &#8216;#attributes&#8217; =&gt; array(&#8216;onClick&#8217; =&gt; &#8216;location.replace(\&#8221;. $_SERVER['HTTP_REFERER'] .&#8217;\'); return false;&#8217;),<br />
        &#8216;#value&#8217; =&gt; t(&#8216;Cancel&#8217;),<br />
    );<br />
?&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dmitry</title>
		<link>http://www.lacisoft.com/blog/2009/10/05/how-to-add-a-cancel-button-to-drupal-forms/comment-page-1/#comment-1625</link>
		<dc:creator>Dmitry</dc:creator>
		<pubDate>Thu, 30 Sep 2010 20:38:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.lacisoft.com/blog/?p=288#comment-1625</guid>
		<description>Sometimes you can&#039;t just redirect user using link. For example when you need to perform some actions on cancel. Here is an example how to really cancel Drupal &quot;required field&quot; validation http://devengineering.com/best-practices/drupal/cancellation-required-validation-drupal-6</description>
		<content:encoded><![CDATA[<p>Sometimes you can&#8217;t just redirect user using link. For example when you need to perform some actions on cancel. Here is an example how to really cancel Drupal &#8220;required field&#8221; validation <a href="http://devengineering.com/best-practices/drupal/cancellation-required-validation-drupal-6" rel="nofollow">http://devengineering.com/best-practices/drupal/cancellation-required-validation-drupal-6</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hnd</title>
		<link>http://www.lacisoft.com/blog/2009/10/05/how-to-add-a-cancel-button-to-drupal-forms/comment-page-1/#comment-783</link>
		<dc:creator>hnd</dc:creator>
		<pubDate>Sun, 16 May 2010 17:56:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.lacisoft.com/blog/?p=288#comment-783</guid>
		<description>it works.. thanks a lot..</description>
		<content:encoded><![CDATA[<p>it works.. thanks a lot..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: xyz</title>
		<link>http://www.lacisoft.com/blog/2009/10/05/how-to-add-a-cancel-button-to-drupal-forms/comment-page-1/#comment-764</link>
		<dc:creator>xyz</dc:creator>
		<pubDate>Mon, 22 Feb 2010 07:01:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.lacisoft.com/blog/?p=288#comment-764</guid>
		<description>super coding,it is working fine</description>
		<content:encoded><![CDATA[<p>super coding,it is working fine</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sim6</title>
		<link>http://www.lacisoft.com/blog/2009/10/05/how-to-add-a-cancel-button-to-drupal-forms/comment-page-1/#comment-755</link>
		<dc:creator>sim6</dc:creator>
		<pubDate>Wed, 27 Jan 2010 13:31:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.lacisoft.com/blog/?p=288#comment-755</guid>
		<description>Hi,

The next code uses javascript:

// hook_form()
function myform_form($form_state, $value) {
  $form[&#039;cancel&#039;] = array(
	&#039;#type&#039; =&gt; &#039;button&#039;,
	&#039;#attributes&#039; =&gt; array(&#039;onClick&#039; =&gt; &#039;location.replace(&quot;&#039;. referer_uri() .&#039;&quot;); return false;&#039;),
	&#039;#value&#039; =&gt; t(&#039;Cancel&#039;),
  );
}


Enjoy it!

</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>The next code uses javascript:</p>
<p>// hook_form()<br />
function myform_form($form_state, $value) {<br />
  $form['cancel'] = array(<br />
	&#8216;#type&#8217; =&gt; &#8216;button&#8217;,<br />
	&#8216;#attributes&#8217; =&gt; array(&#8216;onClick&#8217; =&gt; &#8216;location.replace(&#8220;&#8216;. referer_uri() .&#8217;&#8221;); return false;&#8217;),<br />
	&#8216;#value&#8217; =&gt; t(&#8216;Cancel&#8217;),<br />
  );<br />
}</p>
<p>Enjoy it!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://www.lacisoft.com/blog/2009/10/05/how-to-add-a-cancel-button-to-drupal-forms/comment-page-1/#comment-733</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Thu, 24 Dec 2009 20:33:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.lacisoft.com/blog/?p=288#comment-733</guid>
		<description>Thanks for this one!

IMO, a button is a much better solution than the &quot;text link&quot; version. Users (psychologically?) &quot;feel safer&quot; clicking a button to cancel.

From what I could tell, the validation function was OK because $form_state[&#039;values&#039;] still had the original content (which was valid). While $form_state[&#039;clicked_button&#039;][&#039;#post&#039;] had the current (potentially invalid) data. Though I&#039;m a newbie and may be interpreting it incorrectly.

Thanks again, it worked fine for me (Drupal 6.15).</description>
		<content:encoded><![CDATA[<p>Thanks for this one!</p>
<p>IMO, a button is a much better solution than the &#8220;text link&#8221; version. Users (psychologically?) &#8220;feel safer&#8221; clicking a button to cancel.</p>
<p>From what I could tell, the validation function was OK because $form_state['values'] still had the original content (which was valid). While $form_state['clicked_button']['#post'] had the current (potentially invalid) data. Though I&#8217;m a newbie and may be interpreting it incorrectly.</p>
<p>Thanks again, it worked fine for me (Drupal 6.15).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MadtownLems</title>
		<link>http://www.lacisoft.com/blog/2009/10/05/how-to-add-a-cancel-button-to-drupal-forms/comment-page-1/#comment-731</link>
		<dc:creator>MadtownLems</dc:creator>
		<pubDate>Wed, 16 Dec 2009 16:23:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.lacisoft.com/blog/?p=288#comment-731</guid>
		<description>This is a good start, but doesn&#039;t this get run AFTER any validation, such as Required fields?

I tried it out on a form with a required field, and that&#039;s what kept happening. Pushing cancel would take me back to the same page telling me the title was required.  But if i entered a title, and then pushed cancel, it would work.

Thoughts?

and thanks!</description>
		<content:encoded><![CDATA[<p>This is a good start, but doesn&#8217;t this get run AFTER any validation, such as Required fields?</p>
<p>I tried it out on a form with a required field, and that&#8217;s what kept happening. Pushing cancel would take me back to the same page telling me the title was required.  But if i entered a title, and then pushed cancel, it would work.</p>
<p>Thoughts?</p>
<p>and thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rsevero</title>
		<link>http://www.lacisoft.com/blog/2009/10/05/how-to-add-a-cancel-button-to-drupal-forms/comment-page-1/#comment-702</link>
		<dc:creator>rsevero</dc:creator>
		<pubDate>Thu, 26 Nov 2009 20:57:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.lacisoft.com/blog/?p=288#comment-702</guid>
		<description>Answering your last question: not exactly.

This solution presents a problem if you have any &quot;required&quot; fields and any of them is empty when the user tries to cancel. You got a &quot;required field&quot; error message and the cancelation fails.

Better to define the &quot;Cancel&quot; button as a link to the page you want to take your users on cancelation. You can do it defining a &quot;#markup&#039; type element in the form:

    $form[&#039;cancel&#039;] = array(
        &#039;#value&#039; =&gt; sprintf(&quot;&lt;a href=&#039;%s&#039; rel=&quot;nofollow&quot;&gt;%s&lt;/a&gt;&quot;, URL_TO_GO, t(&#039;Cancel&#039;)),
    );</description>
		<content:encoded><![CDATA[<p>Answering your last question: not exactly.</p>
<p>This solution presents a problem if you have any &#8220;required&#8221; fields and any of them is empty when the user tries to cancel. You got a &#8220;required field&#8221; error message and the cancelation fails.</p>
<p>Better to define the &#8220;Cancel&#8221; button as a link to the page you want to take your users on cancelation. You can do it defining a &#8220;#markup&#8217; type element in the form:</p>
<p>    $form['cancel'] = array(<br />
        &#8216;#value&#8217; =&gt; sprintf(&#8220;<a href='%s' rel="nofollow">%s</a>&#8220;, URL_TO_GO, t(&#8216;Cancel&#8217;)),<br />
    );</p>
]]></content:encoded>
	</item>
</channel>
</rss>

