htmlspecialchars () expects parameter 1 to be string, object given

1

I have made a new form element, a zend_form_element that inherits from the text field of zf1 .

The fact is that when I use it in a form it sends me this warning:

  

PHP Warning: htmlspecialchars () expects parameter 1 to be string, object given in /srv/www/code/library/Zend/View/Abstract.php on line 905

and when I submit, it sends me a response to http 502. It seems that when the form is not valid and it is possible to repaint the fields, an error occurs.

Can you think of what could happen to launch this message?

public function init()
{
    parent::init();

    $this->setDecorators(array(
        'PrepareElements',
        array('ViewScript', array('viewScript' => 'user/new-provider.phtml')),
    ));

    $this->removeElement('user_id');
    $this->userElement = new Admin_Form_Element_NewOrExistingUser(array(
        'name' => 'user_email',
        'label' => 'Email',
        'required' => true,
        'description' => 'Introduce el email del usuario existente, o crea uno nuevo',
    ));
}

class Admin_Form_Element_NewOrExistingUser extends Zend_Form_Element_Text
{
    public function init() 
    {
        parent::init();

        $this->setOptions(array(

            'label' => $this->getLabel(),
            'description' =>  $this->description,
            'autofocus' => 'true',
            'size' => 40,
            'maxlength' => 200,
            'decorators' => array(
                'ViewHelper',
                'Errors',
                array('Description', array('escape' => false, 'tag' => 'p',    'class' => 'description', 'placement' => 'prepend')),
                array('HtmlTag',     array('tag' => 'dd')),
                array('Label',       array('tag' => 'dt')),
            ),
            'value' => null,
            'disableTranslator' => true,
            'filters' => array('StringTrim'),
        ));            
    }

    public function isValidElement($value) 
    {   
        $valid = true;
        if ($this->required && $value == null) {
            $this->addError("El campo del usuario es obligatorio, introduce un usuario válido");
            $valid = false;
        }
        return $valid;
    }
}
    
asked by davidplpz 08.08.2016 в 13:48
source

1 answer

1

The bug came from the controller. I was not setting the field well and hence the error. This is the code:

public function validateUser($form){
  if(!$form->isValid($this->getRequest()->getPost())){
    $user = $form->getUser();
    //$form->getElement('user_mail')->setValue($user); // esto esta mal porque es un objeto
    //$form->getElement('user_mail')->setValue($user->getName());
  }
}
    
answered by 08.08.2016 / 18:27
source