Zend Framework

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

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Duplicate
  • Affects Version/s: 1.9.3
  • Fix Version/s: 1.9.5
  • Component/s: Zend_Form, Zend_View
  • Labels:
    None

Description

Source File: Zend\View\Abstract.php : 850
Function Name: htmlspecialchars
Error String: htmlspecialchars() expects parameter 1 to be string, array given
Error Type: E_WARNING

Function Name: htmlspecialchars
Function Arguments:
1. array (
'isEmpty' => 'Value is required and can\'t be empty',
)
2. 2
3. 'utf-8'

BackTrace:

htmlspecialchars()
Zend_View::escape() at Zend\View\Abstract.php : 850
Zend_View::formErrors() at Zend\View\Helper\FormErrors.php : 80
Zend_View_Helper_FormErrors::formErrors()
Zend_View::__call() at Zend\View\Abstract.php : 342
Zend_View::render() at Zend\Form\Decorator\Errors.php : 60
Zend_Form_Decorator_Errors::render() at Zend\Form.php : 2626
Default_forms_UserForm::__toString() at Zend\Form.php : 2641

Issue Links

Activity

Hide
Ryan Mauger added a comment -

Could you supply some code to reproduce this issue, or the use-case in which is was produced.

Show
Ryan Mauger added a comment - Could you supply some code to reproduce this issue, or the use-case in which is was produced.
Hide
Krzysztof Szatanik added a comment - - edited

public function testAction() {

$this->_helper->layout->disableLayout();
$this->getFrontController()->setParam( 'noViewRenderer', true );

$form = new Zend_Form ( );
$form->addElement ( 'text', 'test', array (
'required' => true,
'label' => 'Test'
) );
$form->addElement ( 'submit', 'submit', array (
'label' => 'Submit'
) );

$form->setMethod ( 'post' );

$form->addDecorator ( 'Errors', array( 'class' => 'my-errors') );

if ($this->getRequest ()->isPost ()) {
if ($form->isValid ( $this->getRequest ()->getPost () )) { echo 'ok'; }
}

echo $form;
}

Submit empty form to trigger "required" error

Show
Krzysztof Szatanik added a comment - - edited public function testAction() { $this->_helper->layout->disableLayout(); $this->getFrontController()->setParam( 'noViewRenderer', true ); $form = new Zend_Form ( ); $form->addElement ( 'text', 'test', array ( 'required' => true, 'label' => 'Test' ) ); $form->addElement ( 'submit', 'submit', array ( 'label' => 'Submit' ) ); $form->setMethod ( 'post' ); $form->addDecorator ( 'Errors', array( 'class' => 'my-errors') ); if ($this->getRequest ()->isPost ()) { if ($form->isValid ( $this->getRequest ()->getPost () )) { echo 'ok'; } } echo $form; } Submit empty form to trigger "required" error
Hide
Matthew Weier O'Phinney added a comment -

This duplicates the findings in ZF-4915, which is currently resolved in trunk and the 1.9 release branch; changes will be released in 1.9.5.

Show
Matthew Weier O'Phinney added a comment - This duplicates the findings in ZF-4915, which is currently resolved in trunk and the 1.9 release branch; changes will be released in 1.9.5.
Hide
Lars Gierth added a comment -

This is not being fixed in 1.9.5.

htmlspecialchars() is still failing in connection with the NotEmpty validator.

Show
Lars Gierth added a comment - This is not being fixed in 1.9.5. htmlspecialchars() is still failing in connection with the NotEmpty validator.
Hide
Lars Gierth added a comment -

This is the form I'm trying to use, I switched to Zend_Validate_StringLength instead of NotEmpty.

class Conference_Form_Site_Speaker_Register extends Zend_Form
{
/**
*

  • Conference_Form_Site_Speaker_Register::init
    *
  • @return void
    */
    public function init() { $this->setAttrib('id', 'form-speaker-register'); $surname = new Zend_Form_Element_Text(array( 'name' => 'surname', 'id' => 'form-speaker-register-surname', 'label' => 'Surname', 'class' => 'text' )); $surname->setRequired(true) ->addValidator('stringLength', false, array(1)); $this->addElement($surname); $forename = new Zend_Form_Element_Text(array( 'name' => 'forename', 'id' => 'form-speaker-register-forename', 'label' => 'Forename', 'class' => 'text' )); $forename->setRequired(true) ->addValidator('stringLength', false, array(1)); $this->addElement($forename); $company = new Zend_Form_Element_Text(array( 'name' => 'company', 'id' => 'form-speaker-register-company', 'label' => 'Company', 'class' => 'text' )); $company->setRequired(true) ->addValidator('stringLength', false, array(1)); $this->addElement($company); $email = new Zend_Form_Element_Text(array( 'name' => 'email', 'id' => 'form-speaker-register-email', 'label' => 'E-mail address', 'class' => 'text' )); $email->setRequired(true) ->addValidator('EmailAddress'); $this->addElement($email); $website = new Zend_Form_Element_Text(array( 'name' => 'website', 'id' => 'form-speaker-register-website', 'label' => 'Website', 'class' => 'text' )); $website->setRequired(true) ->setAllowEmpty(true); $this->addElement($website); $password = new Zend_Form_Element_Password(array( 'name' => 'password', 'id' => 'form-speaker-register-password', 'label' => 'Password', 'class' => 'text' )); $password->setRequired(true) ->addValidator('stringLength', false, array(5)); $this->addElement($password); $picture = new Zend_Form_Element_File(array( 'name' => 'picture', 'id' => 'form-speaker-register-picture', 'label' => 'Picture', 'class' => 'picture' )); $picture->setRequired(true); $this->addElement($picture); $abstract = new Zend_Form_Element_Textarea(array( 'name' => 'abstract', 'id' => 'form-speaker-register-abstract', 'label' => 'Abstract', 'class' => 'text_area' )); $abstract->setRequired(true) ->setAllowEmpty(true); $this->addElement($abstract); $this->addElement('submit', 'submit', array( 'id' => 'form-speaker-register-submit', 'class' => 'submit' )); }

public function __toString()

{ $this->setDecorators(array( 'Errors', 'FormElements', 'Form', )); return parent::__toString(); }

}

Show
Lars Gierth added a comment - This is the form I'm trying to use, I switched to Zend_Validate_StringLength instead of NotEmpty. class Conference_Form_Site_Speaker_Register extends Zend_Form { /** *
  • Conference_Form_Site_Speaker_Register::init *
  • @return void */ public function init() { $this->setAttrib('id', 'form-speaker-register'); $surname = new Zend_Form_Element_Text(array( 'name' => 'surname', 'id' => 'form-speaker-register-surname', 'label' => 'Surname', 'class' => 'text' )); $surname->setRequired(true) ->addValidator('stringLength', false, array(1)); $this->addElement($surname); $forename = new Zend_Form_Element_Text(array( 'name' => 'forename', 'id' => 'form-speaker-register-forename', 'label' => 'Forename', 'class' => 'text' )); $forename->setRequired(true) ->addValidator('stringLength', false, array(1)); $this->addElement($forename); $company = new Zend_Form_Element_Text(array( 'name' => 'company', 'id' => 'form-speaker-register-company', 'label' => 'Company', 'class' => 'text' )); $company->setRequired(true) ->addValidator('stringLength', false, array(1)); $this->addElement($company); $email = new Zend_Form_Element_Text(array( 'name' => 'email', 'id' => 'form-speaker-register-email', 'label' => 'E-mail address', 'class' => 'text' )); $email->setRequired(true) ->addValidator('EmailAddress'); $this->addElement($email); $website = new Zend_Form_Element_Text(array( 'name' => 'website', 'id' => 'form-speaker-register-website', 'label' => 'Website', 'class' => 'text' )); $website->setRequired(true) ->setAllowEmpty(true); $this->addElement($website); $password = new Zend_Form_Element_Password(array( 'name' => 'password', 'id' => 'form-speaker-register-password', 'label' => 'Password', 'class' => 'text' )); $password->setRequired(true) ->addValidator('stringLength', false, array(5)); $this->addElement($password); $picture = new Zend_Form_Element_File(array( 'name' => 'picture', 'id' => 'form-speaker-register-picture', 'label' => 'Picture', 'class' => 'picture' )); $picture->setRequired(true); $this->addElement($picture); $abstract = new Zend_Form_Element_Textarea(array( 'name' => 'abstract', 'id' => 'form-speaker-register-abstract', 'label' => 'Abstract', 'class' => 'text_area' )); $abstract->setRequired(true) ->setAllowEmpty(true); $this->addElement($abstract); $this->addElement('submit', 'submit', array( 'id' => 'form-speaker-register-submit', 'class' => 'submit' )); }
public function __toString() { $this->setDecorators(array( 'Errors', 'FormElements', 'Form', )); return parent::__toString(); } }

People

Vote (0)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: