title: String to be escaped was not valid UTF-8 or could not be converted zend 2.3
body: <p>Hello all I am creating form on zend 2.3 framework. And getting the following error message String to be escaped was not valid UTF-8 or could not be converted. In my editor zend studio that is I changed encoding to utf-8 before importing the project into a workspace. This is the stack tracce of this error:</p>
  
  <pre><code>#0 C:\xampp\htdocs\disability\vendor\zendframework\zendframework\library\Zend\Escaper\Escaper.php(162): Zend\Escaper\Escaper-&gt;toUtf8('?????????')
  #1 C:\xampp\htdocs\disability\vendor\zendframework\zendframework\library\Zend\View\Helper\EscapeHtmlAttr.php(25): Zend\Escaper\Escaper-&gt;escapeHtmlAttr('?????????')
  #2 C:\xampp\htdocs\disability\vendor\zendframework\zendframework\library\Zend\View\Helper\Escaper\AbstractHelper.php(51): Zend\View\Helper\EscapeHtmlAttr-&gt;escape('?????????')
  #3 C:\xampp\htdocs\disability\vendor\zendframework\zendframework\library\Zend\Form\View\Helper\AbstractHelper.php(233): Zend\View\Helper\Escaper\AbstractHelper-&gt;__invoke('?????????')
  #4 C:\xampp\htdocs\disability\vendor\zendframework\zendframework\library\Zend\Form\View\Helper\FormInput.php(128): Zend\Form\View\Helper\AbstractHelper-&gt;createAttributesString(Array)
  #5 C:\xampp\htdocs\disability\vendor\zendframework\zendframework\library\Zend\Form\View\Helper\FormInput.php(101): Zend\Form\View\Helper\FormInput-&gt;render(Object(Zend\Form\Element\Submit))
  #6 [internal function]: Zend\Form\View\Helper\FormInput-&gt;__invoke(Object(Zend\Form\Element\Submit))
  #7 C:\xampp\htdocs\disability\vendor\zendframework\zendframework\library\Zend\View\Renderer\PhpRenderer.php(399): call_user_func_array(Object(Zend\Form\View\Helper\FormSubmit), Array)
  #8 C:\xampp\htdocs\disability\module\Admin\view\admin\admin\addstudent.phtml(36): Zend\View\Renderer\PhpRenderer-&gt;__call('formSubmit', Array)
  #9 C:\xampp\htdocs\disability\module\Admin\view\admin\admin\addstudent.phtml(36): Zend\View\Renderer\PhpRenderer-&gt;formSubmit(Object(Zend\Form\Element\Submit))
  #10 C:\xampp\htdocs\disability\vendor\zendframework\zendframework\library\Zend\View\Renderer\PhpRenderer.php(506): include('C:\xampp\htdocs...')
  #11 C:\xampp\htdocs\disability\vendor\zendframework\zendframework\library\Zend\View\View.php(205): Zend\View\Renderer\PhpRenderer-&gt;render(Object(Zend\View\Model\ViewModel))
  #12 C:\xampp\htdocs\disability\vendor\zendframework\zendframework\library\Zend\View\View.php(233): Zend\View\View-&gt;render(Object(Zend\View\Model\ViewModel))
  #13 C:\xampp\htdocs\disability\vendor\zendframework\zendframework\library\Zend\View\View.php(198): Zend\View\View-&gt;renderChildren(Object(Zend\View\Model\ViewModel))
  #14 C:\xampp\htdocs\disability\vendor\zendframework\zendframework\library\Zend\Mvc\View\Http\DefaultRenderingStrategy.php(103): Zend\View\View-&gt;render(Object(Zend\View\Model\ViewModel))
  #15 [internal function]: Zend\Mvc\View\Http\DefaultRenderingStrategy-&gt;render(Object(Zend\Mvc\MvcEvent))
  #16 C:\xampp\htdocs\disability\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
  #17 C:\xampp\htdocs\disability\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(207): Zend\EventManager\EventManager-&gt;triggerListeners('render', Object(Zend\Mvc\MvcEvent), Array)
  #18 C:\xampp\htdocs\disability\vendor\zendframework\zendframework\library\Zend\Mvc\Application.php(352): Zend\EventManager\EventManager-&gt;trigger('render', Object(Zend\Mvc\MvcEvent))
  #19 C:\xampp\htdocs\disability\vendor\zendframework\zendframework\library\Zend\Mvc\Application.php(327): Zend\Mvc\Application-&gt;completeRequest(Object(Zend\Mvc\MvcEvent))
  #20 C:\xampp\htdocs\disability\public\index.php(17): Zend\Mvc\Application-&gt;run()
  #21 {main}
  </code></pre>
  
  <p>Here is the code of the form's view </p>
  
  <pre><code>&lt;?php
   // module/Album/view/album/album/add.phtml:
  
   $title = 'add student';
   $this-&gt;headTitle($title);
   ?&gt;
   &lt;h1&gt;&lt;?php echo $this-&gt;escapeHtml($title); ?&gt;&lt;/h1&gt;
  
  &lt;div id="allarea"&gt;
  &lt;?php
  // $form-&gt;setAttribute('action', $this-&gt;url('Admin\Controller\AdminController', array('action' =&gt; 'Admin\Form\AddstudentForm')));
  $form-&gt;setAttribute('action', $this-&gt;url('admin', array('action' =&gt; 'addstudent')));
  
   $form-&gt;prepare();
  
   echo $this-&gt;form()-&gt;openTag($form);
   echo $this-&gt;formRow($form-&gt;get('fio'));
   echo $this-&gt;formRow($form-&gt;get('gender'));
   echo $this-&gt;formRow($form-&gt;get('birthdate'));
   echo $this-&gt;formRow($form-&gt;get('edge'));
   echo $this-&gt;formRow($form-&gt;get('university'));
   echo $this-&gt;formRow($form-&gt;get('group'));
   echo $this-&gt;formRow($form-&gt;get('department'));
   echo $this-&gt;formRow($form-&gt;get('grate'));
   echo $this-&gt;formRow($form-&gt;get('enterence'));
   echo $this-&gt;formRow($form-&gt;get('financesource'));
   echo $this-&gt;formRow($form-&gt;get('studyform'));
   echo $this-&gt;formRow($form-&gt;get('homeaddress'));
   echo $this-&gt;formRow($form-&gt;get('actualaddress'));
   echo $this-&gt;formRow($form-&gt;get('phone'));
   echo $this-&gt;formRow($form-&gt;get('workplace'));
  
  
   echo $this-&gt;formRow($form-&gt;get('services'));
   echo $this-&gt;formSubmit($form-&gt;get('submit'));
   echo $this-&gt;form()-&gt;closeTag();
  ?&gt;
  
  
  
  &lt;/div&gt;
  </code></pre>
  
  <p>here is the file Form/Addstudent.php</p>
  
  <pre><code>&lt;?php
  namespace Admin\Form;
  
  use Zend\Form\Form;
  
  class AddstudentForm extends Form
  {
      public function __construct($name = null)
      {
          // we want to ignore the name passed
          parent::__construct('addstudent');
  
  
          $this-&gt;add(array(
              'name' =&gt; 'fio',
              'type' =&gt; 'Text',
              'options' =&gt; array(
                  'label' =&gt; 'fio',
              ),
          ));
          $this-&gt;add(array(
              'name' =&gt; 'gender',
              'type' =&gt; 'Zend\Form\Element\Radio',
              'options' =&gt; array(
                  'label' =&gt; 'gender',
                  'value_options' =&gt; array(
                      '0' =&gt; 'm',
                      '1' =&gt; 'f',
                  ),
  
              ),
          ));
          $this-&gt;add(array(
              'name' =&gt; 'birthdate',
              'type' =&gt; 'Text',
              'options' =&gt; array(
                  'label' =&gt; 'birthdate',
              ),
          ));
  
          $this-&gt;add(array(
              'name' =&gt; 'edge',
              'type' =&gt; 'Text',
              'options' =&gt; array(
                  'label' =&gt; 'edge',
              ),
          ));
  
          $this-&gt;add(array(
              'name' =&gt; 'university',
              'type' =&gt; 'Text',
              'options' =&gt; array(
                  'label' =&gt; 'vuz',
              ),
          ));
          $this-&gt;add(array(
              'name' =&gt; 'group',
              'type' =&gt; 'Text',
              'options' =&gt; array(
                  'label' =&gt; 'gruoup',
              ),
          ));
          $this-&gt;add(array(
              'name' =&gt; 'department',
              'type' =&gt; 'Text',
              'options' =&gt; array(
                  'label' =&gt; 'department',
              ),
          ));
          $this-&gt;add(array(
              'name' =&gt; 'grate',
              'type' =&gt; 'Zend\Form\Element\Radio',
              'options' =&gt; array(
                  'label' =&gt; 'greate',
                  'value_options' =&gt; array(
                      '0' =&gt; '1',
                      '1' =&gt; '2',
                      '2' =&gt; '3',
                      '3' =&gt; '4',
                      '4' =&gt; '5',
                      '5' =&gt; '6',
  
                  ),
  
              ),
          ));
          $this-&gt;add(array(
              'name' =&gt; 'enterence',
              'type' =&gt; 'Text',
              'options' =&gt; array(
                  'label' =&gt; 'enterance year',
              ),
          ));
  
          $this-&gt;add(array(
              'name' =&gt; 'financesource',
              'type' =&gt; 'Zend\Form\Element\Radio',
              'options' =&gt; array(
                  'label' =&gt; 'finance source',
                  'value_options' =&gt; array(
                      '0' =&gt; 'butget',
                      '1' =&gt; 'contract',
  
                  ),
  
              ),
          ));
  
          $this-&gt;add(array(
              'name' =&gt; 'studyform',
              'type' =&gt; 'Zend\Form\Element\Radio',
              'options' =&gt; array(
                  'label' =&gt; 'studyform',
                  'value_options' =&gt; array(
                      '0' =&gt; 'on side',
                      '1' =&gt; 'distance',
  
                  ),
  
              ),
          ));
  
          $this-&gt;add(array(
              'name' =&gt; 'homeaddress',
              'type' =&gt; 'Text',
              'options' =&gt; array(
                  'label' =&gt; 'Home address',
              ),
          ));
  
          $this-&gt;add(array(
              'name' =&gt; 'actualaddress',
              'type' =&gt; 'Text',
              'options' =&gt; array(
                  'label' =&gt; 'actual address',
              ),
          ));
          $this-&gt;add(array(
              'name' =&gt; 'phone',
              'type' =&gt; 'Text',
              'options' =&gt; array(
                  'label' =&gt; 'phone',
              ),
          ));
  
          $this-&gt;add(array(
              'name' =&gt; 'workplace',
              'type' =&gt; 'Text',
              'options' =&gt; array(
                  'label' =&gt; 'workplace',
              ),
          ));
          $this-&gt;add(array(
              'name' =&gt; 'services',
              'type' =&gt; 'Zend\Form\Element\Textarea',
              'options' =&gt; array(
                  'label' =&gt; 'services',
              ),
          ));
  
          $this-&gt;add(array(
              'name' =&gt; 'submit',
              'type' =&gt; 'Submit',
              'attributes' =&gt; array(
                  'value' =&gt; 'save',
                  'id' =&gt; 'submitbutton',
              ),
          ));
      }
  }
  </code></pre>
  
  <p>this is the filter</p>
  
  <pre><code>&lt;?php 
  namespace admin\Model;
  
   // Add these import statements
   use Zend\InputFilter\InputFilter;
   use Zend\InputFilter\InputFilterAwareInterface;
   use Zend\InputFilter\InputFilterInterface;
  
   class Admin implements InputFilterAwareInterface
   {
       public $fio;
       public $gender;
       public $birthdate;
       public $edge;
       public $university;
       public $group;
       public $department;
       public $grate;
       public $enterence;
       public $financesource;
       public $studyform;
       public $homeaddress;
       public $actualaddress;
       public $phone;
       public $workplace;
       public $services;
       protected $inputFilter;                       // &lt;-- Add this variable
  
       public function exchangeArray($data)
       {
           $this-&gt;fio = (isset($data['fio'])) ? $data['fio'] : null;
          // $this-&gt;title  = (isset($data['title']))  ? $data['title']  : null;
           $this-&gt;gender = (isset($data['gender'])) ? $data['gender'] : null;
           $this-&gt;birthdate = (isset($data['birthdate'])) ? $data['birthdate'] : null;
           $this-&gt;edge = (isset($data['edge'])) ? $data['edge'] : null;
           $this-&gt;university = (isset($data['university'])) ? $data['university'] : null;
           $this-&gt;group = (isset($data['group'])) ? $data['group'] : null;
           $this-&gt;department = (isset($data['department'])) ? $data['department'] : null;
           $this-&gt;grate = (isset($data['grate'])) ? $data['grate'] : null;
           $this-&gt;enterence = (isset($data['enterence'])) ? $data['enterence'] : null;
           $this-&gt;financesource = (isset($data['financesource'])) ? $data['financesource'] : null;
           $this-&gt;studyform = (isset($data['studyform'])) ? $data['studyform'] : null;
           $this-&gt;homeaddress = (isset($data['homeaddress'])) ? $data['homeaddress'] : null;
           $this-&gt;actualaddress = (isset($data['actualaddress'])) ? $data['actualaddress'] : null;
           $this-&gt;phone = (isset($data['phone'])) ? $data['phone'] : null;
           $this-&gt;workplace = (isset($data['workplace'])) ? $data['workplace'] : null;
           $this-&gt;services = (isset($data['services'])) ? $data['services'] : null;
           $escaper = new Zend\Escaper\Escaper('utf-8');
       }
  
       // Add content to these methods:
       public function setInputFilter(InputFilterInterface $inputFilter)
       {
           throw new \Exception("Not used");
       }
  
       public function getInputFilter()
       {
           if (!$this-&gt;inputFilter) {
               $inputFilter = new InputFilter();
  
  
               $inputFilter-&gt;add(array(
                   'name'     =&gt; 'fio',
                   'required' =&gt; true,
                   'filters'  =&gt; array(
                       array('name' =&gt; 'StripTags'),
                       array('name' =&gt; 'StringTrim'),
                   ),
                   'validators' =&gt; array(
                       array(
                           'name'    =&gt; 'StringLength',
                           'options' =&gt; array(
                               'encoding' =&gt; 'UTF-8',
                               'min'      =&gt; 1,
                               'max'      =&gt; 100,
                           ),
                       ),
                   ),
               ));
  
               $inputFilter-&gt;add(array(
                   'name'     =&gt; 'birthdate',
                   'required' =&gt; true,
                   'filters'  =&gt; array(
                       array('name' =&gt; 'StripTags'),
                       array('name' =&gt; 'StringTrim'),
                   ),
                   'validators' =&gt; array(
                       array(
                           'name'    =&gt; 'StringLength',
                           'options' =&gt; array(
                               'encoding' =&gt; 'UTF-8',
                               'min'      =&gt; 1,
                               'max'      =&gt; 100,
                           ),
                       ),
                   ),
               ));
               $inputFilter-&gt;add(array(
                   'name'     =&gt; 'university',
                   'required' =&gt; true,
                   'filters'  =&gt; array(
                       array('name' =&gt; 'StripTags'),
                       array('name' =&gt; 'StringTrim'),
                   ),
                   'validators' =&gt; array(
                       array(
                           'name'    =&gt; 'StringLength',
                           'options' =&gt; array(
                               'encoding' =&gt; 'UTF-8',
                               'min'      =&gt; 1,
                               'max'      =&gt; 100,
                           ),
                       ),
                   ),
               ));
  
               $inputFilter-&gt;add(array(
                   'name'     =&gt; 'group',
                   'required' =&gt; true,
                   'filters'  =&gt; array(
                       array('name' =&gt; 'StripTags'),
                       array('name' =&gt; 'StringTrim'),
                   ),
                   'validators' =&gt; array(
                       array(
                           'name'    =&gt; 'StringLength',
                           'options' =&gt; array(
                               'encoding' =&gt; 'UTF-8',
                               'min'      =&gt; 1,
                               'max'      =&gt; 100,
                           ),
                       ),
                   ),
               ));
  
               $inputFilter-&gt;add(array(
                   'name'     =&gt; 'department',
                   'required' =&gt; true,
                   'filters'  =&gt; array(
                       array('name' =&gt; 'StripTags'),
                       array('name' =&gt; 'StringTrim'),
                   ),
                   'validators' =&gt; array(
                       array(
                           'name'    =&gt; 'StringLength',
                           'options' =&gt; array(
                               'encoding' =&gt; 'UTF-8',
                               'min'      =&gt; 1,
                               'max'      =&gt; 100,
                           ),
                       ),
                   ),
               ));
               $inputFilter-&gt;add(array(
                   'name'     =&gt; 'enterence',
                   'required' =&gt; true,
                   'filters'  =&gt; array(
                       array('name' =&gt; 'StripTags'),
                       array('name' =&gt; 'StringTrim'),
                   ),
                   'validators' =&gt; array(
                       array(
                           'name'    =&gt; 'StringLength',
                           'options' =&gt; array(
                               'encoding' =&gt; 'UTF-8',
                               'min'      =&gt; 1,
                               'max'      =&gt; 100,
                           ),
                       ),
                   ),
               ));
               $inputFilter-&gt;add(array(
                   'name'     =&gt; 'homeaddress',
                   'required' =&gt; true,
                   'filters'  =&gt; array(
                       array('name' =&gt; 'StripTags'),
                       array('name' =&gt; 'StringTrim'),
                   ),
                   'validators' =&gt; array(
                       array(
                           'name'    =&gt; 'StringLength',
                           'options' =&gt; array(
                               'encoding' =&gt; 'UTF-8',
                               'min'      =&gt; 1,
                               'max'      =&gt; 100,
                           ),
                       ),
                   ),
               ));
               $inputFilter-&gt;add(array(
                   'name'     =&gt; 'actualaddress',
                   'required' =&gt; true,
                   'filters'  =&gt; array(
                       array('name' =&gt; 'StripTags'),
                       array('name' =&gt; 'StringTrim'),
                   ),
                   'validators' =&gt; array(
                       array(
                           'name'    =&gt; 'StringLength',
                           'options' =&gt; array(
                               'encoding' =&gt; 'UTF-8',
                               'min'      =&gt; 1,
                               'max'      =&gt; 100,
                           ),
                       ),
                   ),
               ));
               $inputFilter-&gt;add(array(
                   'name'     =&gt; 'phone',
                   'required' =&gt; true,
                   'filters'  =&gt; array(
                       array('name' =&gt; 'StripTags'),
                       array('name' =&gt; 'StringTrim'),
                   ),
                   'validators' =&gt; array(
                       array(
                           'name'    =&gt; 'StringLength',
                           'options' =&gt; array(
                               'encoding' =&gt; 'UTF-8',
                               'min'      =&gt; 1,
                               'max'      =&gt; 100,
                           ),
                       ),
                   ),
               ));
               $inputFilter-&gt;add(array(
                   'name'     =&gt; 'workplace',
                   'required' =&gt; false,
                   'filters'  =&gt; array(
                       array('name' =&gt; 'StripTags'),
                       array('name' =&gt; 'StringTrim'),
                   ),
                   'validators' =&gt; array(
                       array(
                           'name'    =&gt; 'StringLength',
                           'options' =&gt; array(
                               'encoding' =&gt; 'UTF-8',
                               'min'      =&gt; 1,
                               'max'      =&gt; 100,
                           ),
                       ),
                   ),
               ));
  
  
               $inputFilter-&gt;add(array(
                   'name'     =&gt; 'services',
                   'required' =&gt; false,
                   'filters'  =&gt; array(
                       array('name' =&gt; 'StripTags'),
                       array('name' =&gt; 'StringTrim'),
                   ),
                   'validators' =&gt; array(
                       array(
                           'name'    =&gt; 'StringLength',
                           'options' =&gt; array(
                               'encoding' =&gt; 'UTF-8',
                               'min'      =&gt; 1,
                               'max'      =&gt; 2000,
                           ),
                       ),
                   ),
               ));
  
           }
               $this-&gt;inputFilter = $inputFilter;
  
           return $this-&gt;inputFilter;
       }
   }
   ?&gt;
  </code></pre>