the most awesome guy ever.

The Blog of Darryl E. Clarke

  Random musings from a jaded coder who just needs a hug.

Posts Tagged ‘xhtml’

Posting Defaults for Checkboxes

Wednesday, September 24th, 2008

I was playing around with Zend_Form a little while ago and I realized they did something neat with checkboxes.

Everytime I created a checkbox, Zend made two.

<input id="optInDefault" name="optIn" type="hidden" value="n" />
<input id="optIn" name="optIn" type="checkbox" value="y" />

One hidden, and one not.  This is handy because when the user doesn’t check it – the hidden value gets posted. When the checkbox is selected, that value overrides the hidden one.

This also works for radio buttons, or any other form element where you want a default value posted.

Tags: , , , ,
Posted in Coding, PHP, Zend Framework