zrobiłem coś takiego:
public function renderToArray(){
$this->setDisableLoadDefaultDecorators(true);
$this->render(new Zend_View());
$aFormArray['method'] = $this->getMethod();
$aFormArray['action'] = $this->getAction();
$aFormArray['enctype'] = $this->getEnctype();
$aFormArray['errors'] = $this->getErrors();
$i=0;
foreach ($this->getElements() as $sKey => $oElement) {
$aFormArray['elements'][$i]['label'] = $oElement->getLabel();
$aFormArray['elements'][$i]['name'] = $oElement->getName();
$aFormArray['elements'][$i]['id'] = $oElement->getId();
$aFormArray['elements'][$i]['required'] = $oElement->isRequired();
$aFormArray['elements'][$i]['description'] = $oElement->getDescription();
$aFormArray['elements'][$i]['type'] = strtolower(substr( $oElement->getType(), strrpos($oElement->getType(),'_')+1
, strrpos($oElement->getType(),'_'))); $aFormArray['elements'][$i]['html'] = $oElement->renderViewHelper();
$aFormArray['elements'][$i]['value'] = $oElement->getValue();
$i++;
}
return $aFormArray;
}
Teraz mam problem z metodą isValid(), ponieważ jak tylko wchodzę na stronę jeszcze nie klikam submita, a od razu pokazują mi się błędy o nie wprowadzeniu wymaganych pul, oto mój kod:
$oForm = new Form_Community();
$oForm->buildForm();
if($oForm->isValid($_POST)){
$aFormValues = $oForm->getValidValues($_POST);
foreach($oForm->getElements() as $oElement){
$oElement->setValue(null);
}
print_array($aFormValues);
}
$aReturnData['form'] = $oForm->renderToArray($oForm);
[php]
class Form_Community extends CMS_Abstract_Form{
public function buildForm(){
$this->setAction('');
$this->setMethod('post');
$oComunityName = new Zend_Form_Element_Text('community_name');
$oComunityName->setLabel('Nazwa gminy: ');
$oComunityName->setRequired(true)->addErrorMessage('Pole jest wymagane');
$oComunityName->setAttrib('maxlenght',10);
$this->addElement($oComunityName);
$oComunityAdmin = new Zend_Form_Element_Text('community_administrator');
$oComunityAdmin->setLabel('Nazwa zarzadcy drog: ');
$oComunityAdmin->setRequired(true)->addErrorMessage('Pole jest wymagane');
$oComunityAdmin->setAttrib('maxlenght',10);
$oComunityAdmin->setAttrib('classs','input-text');
$this->addElement($oComunityAdmin);
$this->addElement('submit','send',array('label'=>'Wyslij')); }
}
[/php]