Skip to content

Instantly share code, notes, and snippets.

@karbassi
Forked from fc/Project_Form.php
Created August 17, 2008 22:49
Show Gist options
  • Save karbassi/5861 to your computer and use it in GitHub Desktop.
Save karbassi/5861 to your computer and use it in GitHub Desktop.
/*
example usage in subclassed form:
$this->addTableGroup(array(
// row 1
array(
$this->createElement('text', 'name1', array('label' => 'test1')),
$this->createElement('text', 'name2', array('label' => 'test1')),
),
// row 2
array(
$this->createElement('text', 'name1', array('label' => 'test1')),
$this->createElement('text', 'name2', array('label' => 'test1')),
),
));
*/
public function addTableGroup(array $rowsets, $return = false) {
$baseName = 'table-group-';
$form = new Zend_Form_SubForm();
$form->setIsArray(false);
$form->clearDecorators();
$body = new Zend_Form_SubForm();
$body->setIsArray(false);
foreach($rowsets as $id => $rowset){
if( isset($rowset[0][0]) && is_array($rowset[0])) {
//print '<pre>';print_r($rowset);exit;
$rowForm = $this->addTableGroup($rowset, true);
print_r($rowForm);
exit;
$body->addSubForm($rowForm, $baseName.$this->_uid++);
continue;
} else {
//print '<pre>'; print_r($rowset);exit;;
}
$rowForm = new Zend_Form_SubForm();
$rowForm->setIsArray(false);
$rowForm->addElements( $rowset );
$rowForm->setElementDecorators(array(
'ViewHelper',
'Errors',
array('HtmlTag', array('tag' => 'td')),
));
$body->addSubForm($rowForm, $baseName.$this->_uid++);
}
$form->setDecorators(array(
'FormElements',
array('HtmlTag', array('tag' => 'table')),
));
$body->setDecorators(array(
'FormElements',
array('HtmlTag', array('tag' => 'tbody')),
));
$body->setSubFormDecorators(array(
'FormElements',
array('HtmlTag', array('tag'=>'tr')),
));
$form->addSubForm($body, $baseName.$this->_uid++);
$this->addSubForm($form, $baseName.$this->_uid++);
}
$this->addTableGroup(
array(
// Row 1
array(
array(
$this->createElement('text', 'name1-1', array('label' => 'test1-1')),
$this->createElement('text', 'name1-2', array('label' => 'test1-2')),
),
$this->createElement('text', 'name2', array('label' => 'test2')),
),
// Row 2
array(
$this->createElement('text', 'name3', array('label' => 'test3')),
$this->createElement('text', 'name4', array('label' => 'test4')),
)
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment