I would like to add a simple check box to my form:
$element = new Zend_Form_Element_Checkbox('dont');
$element->setDescription('Check this box if you don\'t want to do this action.');
$form->addElement($element);
However, this is what the html looks like:
<dt id="dont-label"> </dt>
<dd id="dont-element">
<input type="hidden" name="dontAttach" value="0">
<input type="checkbox" name="dontAttach" id="dontAttach" value="1">
<p class="description">Don't attach a bulletin. I only want to send an email.</p>
</dd>
The problem with this is that I'm using jQuery to hide all the DT/DDs that have a label of
inside the DT and a hidden element inside the DD (so my html will validate and the hidden elements don't take up space on the page). Is there a way to use a Zend_Form_Element_Checkbox
without having to display a hidden input element? I'd rather not mess with my jQuery code to add more caveats, but I will if I have to.
Solution:
Apparently, I can't/shouldn't remove the hidden element before the checkbox element. So here's my jQuery code to hide all the hidden form elements from being displayed on a page:
//fix zf hidden element from displaying
$('input[type=hidden]').filter(function() {
var noLabel = $(this).closest('dd').prev('dt').html() === ' ';
var onlyChild = $(this).is(':only-child');
if (noLabel && onlyChild) {
return true;
}
return false;
}).each(function() {
$(this).closest('dd').hide()
.prev('dt').hide();
});