Ver Mensaje Individual
  #5 (permalink)  
Antiguo 22/04/2012, 06:11
lolocripto
 
Fecha de Ingreso: diciembre-2010
Mensajes: 79
Antigüedad: 13 años, 4 meses
Puntos: 3
Respuesta: Adding options Zend_Validate_Callback

Si llevas razon, es que yo habia echo una cosa asi

Código PHP:
Ver original
  1. static function CheckEmailSpecial($email, $option){

y lo que claro lo que pasa es que la variable option la envia en el tercer parametro... Es decir si yo pongo lo que me has dicho

Código PHP:
Ver original
  1. static  public function checkEmailSpecial()
  2.     {
  3.         \Zend\Debug::dump(func_get_args());                    
  4.         return false;
  5.     }

Me sale un array de 3 elementos el primero es el elemento value, es decir el email, el segundo son la variable de cada formulario y el tercero es la varible $option...

Ahora tengo otra duda que no se como resolver

Código PHP:
Ver original
  1. ...
  2.    
  3.     class FormExCustomerAccount extends Form{
  4.        
  5.        
  6.         public function init()
  7.         {
  8.            
  9.            
  10.             $element = new Element\Password('cu_password1');
  11.             $element->setLabel('Password1')
  12.             ->setRequired(true)
  13.             ->addFilter('StripTags')
  14.             ->addFilter('StringTrim')
  15.             ->addValidator('NotEmpty')
  16.             ->addValidator('stringLength', false, array(2, 20));
  17.             $this->addElement($element);
  18.                
  19.             //identical le pasamos un array con el token a identificar en este caso el valor de la variable password
  20.             $element = new Element\Password('cu_password2');
  21.             $element->setLabel('Password2')
  22.             ->setRequired(true)
  23.             ->addFilter('StripTags')
  24.             ->addFilter('StringTrim')
  25.             ->addValidator('NotEmpty')
  26.             ->addValidator('identical', false,array(
  27.                     'token' => 'cu_password1',
  28.                     'messages' =>array(
  29.                             'notSame' => 'Passwords are not the same',
  30.                             'missingToken' => 'Problems')))
  31.             ->addValidator('stringLength', false, array(2, 20));
  32.             $this->addElement($element);
  33.            
  34.             $element = new Element\Text('userid');
  35.             $element->setLabel('User id');
  36.             $this->addElement($element);
  37.            
  38.        
  39.             $option=$this->getElement('userid')->getValue();
  40.            
  41.            
  42.             $element = new Element\Text('cu_email');
  43.             $element->setLabel('Email')
  44.             ->setRequired(true)
  45.             ->addValidator('emailAddress')
  46.             ->addValidator('Callback', true, array(
  47.                     'callback' => array(new CustomerLogic(), 'CheckEmailSpecial'),
  48.                     'callbackOptions'=> $option,
  49.                     'messages' =>array(
  50.                             'callbackValue' => 'There is other customer with this email',
  51.                             'callbackInvalid' => 'There is a problem in the system')));
  52.             $this->addElement($element);
  53.            
  54.  
  55.         }
  56.     }
  57.    
  58. ?>

Como hago para meter la variable de userid en opciones, no se como meterlo utilizo $this->getElement('userid')->getValue(), pero no funciona sabrias como puedo decir que el parametro $option de la funcion callback es otro elemento de mi formulario...

Gracias