Created
April 22, 2011 21:22
-
-
Save jonahlyn/937720 to your computer and use it in GitHub Desktop.
Custom render a Zend Form MultiCheckbox element with a viewscript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$audience = new Zend_Form_Element_MultiCheckbox('audience', array( | |
'label' => 'Target Audience', | |
'required' => true, | |
'multiOptions' => array( | |
'students' => 'Students', | |
'faculty' => 'Faculty', | |
'staff' => 'Staff', | |
'stustaf' => 'Student Employees', | |
'retiree' => 'Emeritus/Retiree'), | |
'validators' => array( | |
array('NotEmpty', true, array( | |
'messages' => array( | |
'isEmpty' => 'You must select at least one target audience.' | |
) | |
)) | |
), | |
'decorators' => array( | |
'Errors', | |
array('ViewScript', array('viewScript'=>'multicheckboxview.php')) | |
) | |
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$elem = $this->element; | |
$elemName = $elem->getName(); | |
$values = $elem->getValue(); | |
?> | |
<ul class="condensed"> | |
<?php foreach($elem->getMultiOptions() as $option=>$value){ ?> | |
<li> | |
<input type="checkbox" name="<?php echo $elemName; ?>[]" id="<?php echo $elemName; ?>-<?php echo $option; ?>" value="<?php echo $option; ?>" <?php if($values && in_array($option, $values)){ echo ' checked="checked"'; }?> /> | |
<label for="<?php echo $elemName; ?>-<?php echo $option; ?>"> | |
<?php echo $value; ?> | |
</label> | |
</li> | |
<?php } ?> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you!