Issues

ZF-11716: Problem with filter stringTrim and accented character à

Description

If you use String Trim filter in zend_form_element_text and the last char is the special char "à" the validation StringLength return this message:

Notice: iconv_strlen() [function.iconv-strlen]: Detected an incomplete multibyte character in input string in C:\Programmi\Zend\ZendServer\share\ZendFramework\library\Zend\Validate\StringLength.php on line 234

this is the code to reproduce the error:


class Application_Form_Form extends Zend_Form
{
    public function init()
    {
    $this->setAttrib('accept-charset', 'UTF-8');        
        $this->setName("form");
        $this->setMethod('post');
             
        $this->addElement('text', 'field', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('StringLength', false, array(2, 50,'encoding' => 'UTF-8')),
            ),
            'required'   => true,
            'label'      => 'field',
        ));     
        $this->addElement('submit', 'submit', array(
            'required' => false,
            'ignore'   => true,
            'label'    => 'submit',
        )); 
    }
}

class IndexController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        $form = new Application_Form_Form();
        $request=$this->getRequest();
        if($request->isPost()){
            if($form->isValid($request->getPost())){
            }
        }

        $this->view->form=$form;
    }
}


<?php 
echo $this->form;
?>

Comments

Code tags added

The heading says that StringTrim has problems, but the example error message you gave says that StringLength has the problem. Can you please verify which of the two filters makes problem in your environment and fix heading or example?

Closing as duplicate of ZF-11551