<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Pillage and Plunder &#187; checkbox</title>
	<atom:link href="http://pillageandplunder.net/tag/checkbox/feed/" rel="self" type="application/rss+xml" />
	<link>http://pillageandplunder.net</link>
	<description>Viking's programming blog</description>
	<lastBuildDate>Tue, 25 Aug 2009 00:21:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Rails, PHP, and default check box values</title>
		<link>http://pillageandplunder.net/2009/03/rails-php-and-default-check-box-values/</link>
		<comments>http://pillageandplunder.net/2009/03/rails-php-and-default-check-box-values/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 18:59:34 +0000</pubDate>
		<dc:creator>viking</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[checkbox]]></category>
		<category><![CDATA[html]]></category>

		<guid isPermaLink="false">http://pillageandplunder.net/?p=42</guid>
		<description><![CDATA[The HTML specification dictates that unchecked check boxes should not supply a value in a form submission, which can be problematic for applications wishing to set a flag in a database based on an unchecked check box.  Rails gets around this by using a trick in the check_box helper.  It places a hidden [...]]]></description>
			<content:encoded><![CDATA[<p>The HTML specification dictates that unchecked check boxes should not supply a value in a form submission, which can be problematic for applications wishing to set a flag in a database based on an unchecked check box.  Rails gets around this by <a href="http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#M001580">using a trick</a> in the <code>check_box</code> helper.  It places a hidden input tag with the requested default value <b>directly after</b> the check box tag.</p>
<p>The reason this works is because form parameters are sent in the order that they appear.  This means the hidden input value is submitted <i>after</i> the check box value would be, and Rails gives precedence to parameters appearing earlier in the request.</p>
<p>I tried this in PHP, hoping it would behave the same way.  It doesn&#8217;t.  It turns out that PHP overwrites earlier variables in the request with later ones.  This behavior is dictated by the <a href="http://us2.php.net/manual/en/ini.core.php#ini.request-order">request_order</a> directive (as of PHP 5.3.0, which is still in beta at the time of this post).  The fix is simply to place the hidden input tag before the check box tag.</p>
<p>Hopefully this helps someone avoid the moderate pain I went through figuring all this out.</p>
]]></content:encoded>
			<wfw:commentRss>http://pillageandplunder.net/2009/03/rails-php-and-default-check-box-values/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
