Ver Mensaje Individual
  #2 (permalink)  
Antiguo 10/04/2012, 14:46
Avatar de GatorV
GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 10 meses
Puntos: 2135
Respuesta: Problema con campos dinamicos con Zend_Form

Lamentablemente Zend_Form no tiene esa facilidad, vas a tener que usar los componentes por separado, en el servidor usar Zend_Validate y en el view los form view helpers para crear tu forma un ejemplo puede ser:

Código PHP:
Ver original
  1. public function fooAction()
  2. {
  3.     if ($this->getRequest()->isPost()) {
  4.         $aPostedVars = $this->getRequest()->getPost();
  5.         $Validator = new Zend_Validate_Alpha();
  6.         $aFields = $aPostedVars['multiple'];
  7.         $bHasErrors = false;
  8.         foreach ($aFields as $sNum => $sFieldValue) {
  9.             if (!$Validator->isValid($sFieldValue)) {
  10.                 $aErrors[$sNum] = $Validator->
  11.                 $bHasErrors = true;
  12.             }
  13.         }
  14.        
  15.         if ($bHasErrors) {
  16.             $this->view->errors = $aErrors;
  17.             $this->view->field_values = $aPostedVars['multiple'];
  18.             $this->view->field_count = count($aPostedVars['multiple']);
  19.         } else {
  20.             // Form Valid!
  21.         }
  22.     } else {
  23.         $this->view->field_count = 1;
  24.         $this->view->field_values = array(0 => '');
  25.     }
  26. }
  27.  
  28. // foo.phtml
  29. <?php echo $this->form('test'); ?>
  30.     <?php for($i = 0; $i < $this->field_count; $i++) { ?>
  31.         Input #<?php echo $i; ?>: <?php echo $this->formText('multiple[]', $this->field_values[$i]); ?>
  32.     <?php } ?>
  33. </form>

Así mantienes la persistencia tanto en el cliente como en el servidor, aunque como te digo tienes que hacerlo de una forma más manual ya que Zend_Form por sí solo no tiene ese soporte.

Saludos.