rendered paste body<?PHP
class Pata_Form_Element_MultiCheckboxTable extends Zend_Form_Element_MultiCheckbox
{
protected $_tableElements;
protected $_tableHeadings;
public function setMultiOptions(array $options)
{
foreach ($options as $option)
{
$option->setSeparator('</td><td>');
$option->setDecorators(array('viewhelper'));
}
$this->_tableElements = $options;
}
public function setTableHeadings(array $headings)
{
$this->_tableHeadings = $headings;
}
public function render(Zend_View_Interface $view = null)
{
$html = array();
$html[] = "<table>";
$html[] = "<thead>";
$html[] = "<tr>";
foreach ($this->_tableHeadings as $heading) {
$html[] = "<th>";
$html[] = $heading;
$html[] = "</th>";
}
$html[] = "</tr>";
$html[] = "</thead>";
$html[] = "<tbody>";
foreach ($this->_tableElements as $element) {
$html[] = "<tr>";
$html[] = "<th>";
$html[] = $element->getLabel();
$html[] = "</th>";
$html[] = "<td>";
$html[] = $element->render();
$html[] = "</td>";
$html[] = "</tr>";
}
$html[] = "</tbody>";
$html[] = "</table>";
return implode("\n", $html);
}
}
class Sample_Form extends Zend_Form {
public function init()
{
$elementGrid = array();
// Each of these has three MultiOptions - matching to 'tableheadings' below;
$elementGrid[] = new Zend_Form_Element_MultiCheckbox();
$elementGrid[] = new Zend_Form_Element_MultiCheckbox();
$elementGrid[] = new Zend_Form_Element_MultiCheckbox();
$element = new Pata_Form_Element_MultiCheckboxTable('section_settings', array(
'multioptions' => $sectionElements,
'tableheadings' => array('', 'Top Navigation', 'Bottom Navigation'),
));
}
}