Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Html entities view problem and UTF8?
  • This is real pain... In my admin when I list users the UTF8 strings are shown OK, example this: http://dl.dropbox.com/u/1207859/utf1.png. Characters are OK! But when I click edit to edit an entry then some characters are converted into HTML entities like this: http://dl.dropbox.com/u/1207859/utf2.png. Where is the catch? Data in MySQL is written ok, I use utf8_unicode_ci encoding and collation, my FuelPHP locale end encoding is set to:
    'locale' => 'sl_SI.utf8'
    'encoding' => 'UTF-8' Thanks!
  • Maybe this has something to do with profile_fileds serialization in users table? cause I don't have this issue in other fields!?
  • I am still having problems with this issue. Did someone have the same issue and solved it somehow?
  • Please can someone explain me this: http://dl.dropbox.com/u/1207859/htmlentitiesproblem.png
    Note my name which is echoed int the view with echo $user->profile_fields, but when set as form field value "š" character will be converted into HTML entity š??
    <?php
     echo $user->profile_fields['firstname'];
    ?>
     <div class="control-group">
      <?php echo Form::label('Ime', 'firstname', array('class'=>'control-label')); ?>
      <div class="controls">
       <?php echo Form::input('firstname', Input::post('firstname', isset($user->profile_fields['firstname']) ? $user->profile_fields['firstname'] : ''), array('class' => 'span4')); ?>
      </div>
     </div>
    

    I am running out of ideas here... My database uses utf8_unicode_ci encoding an collation. My locale setting in Fuel is: sl_SI.utf8, and encoding: 'UTF-8'. I am using 'data_type' => 'serialize' in my user model!
  • This is a Form::input class problem... If I manually set form field like then the form value will be ok.
    <input name="test" type="text" value="<?=$user->profile_fields['firstname']?>">
    
    UPDATE 1: I went debugging From::input method and some of my from value string characters gets converted into html entities after calling $attributes = static::prep_value($attributes)!
      if (\Config::get('form.prep_value', true) && empty($attributes['dont_prep']))
      {
       $attributes['value'] = static::prep_value($attributes['value']);
       unset($attributes['dont_prep']);
      }
    

    I would like to understand why this is happening? The weirdest thing is this character is normal displayed in other forms, but not in user form for profile fields!!
  • Can someone explain this: http://dl.dropbox.com/u/1207859/testhtmlentitiesform.png
    echo $user->profile_fields['firstname'] . ' ' . $user->profile_fields['lastname'];
    echo '<br>';
    
    $test = serialize(array('firstname'=>'Urška', 'lastname'=>'Neumüller'));
    var_dump($test);
    
    echo '<br>';
    $test2 = unserialize($test);
    var_dump($test2);
    
    echo '<br>';
    echo '<input type="text" value="'.$test2['firstname'].'">';
    echo '<input type="text" value="'.$test2['lastname'].'">';
    
    echo '<br>';
    echo '<input type="text" value="'.htmlspecialchars($test2['firstname']).'">';
    echo '<input type="text" value="'.htmlspecialchars($test2['lastname']).'">';
    
    echo '<br>';
    echo '<input type="text" value="'.$user->profile_fields['firstname'].'">';
    echo '<input type="text" value="'.$user->profile_fields['lastname'].'">';
    
    echo '<br>';
    echo '<input type="text" value="'.htmlspecialchars($user->profile_fields['firstname']).'">';
    echo '<input type="text" value="'.htmlspecialchars($user->profile_fields['lastname']).'">';
    

    Output here http://dl.dropbox.com/u/1207859/testhtmlentitiesform.png. I still don't know where this problem originates from! Is it my DB is it PHP is it FuelPHP... ?
  • Can you post the code on [url=http://scrp.at,]http://scrp.at,[/url] the forum messes with the encoding as well...
  • Thinking about it, I think the issue here is double encoding. FuelPHP by runs Security::htmlentities() by default on all data send to a view, unless you disable that. This is a security measure. But Form::Input() calls prep_value(), which also calls Security::htmlentities(), causing the value to be encoded twice. By default PHP's htmlentities() will also double encode. For the Security class, I've commited a fix for this a few days ago that will disable double encoding by default. So I suggest you upgrade to 1.1/develop if you're on 1.1 release, or wait a few days, we're about to release a 1.2 which will be based on the current 1.1/develop code.
  • Thinking about it, I think the issue here is double encoding. FuelPHP by runs Security::htmlentities() by default on all data send to a view, unless you disable that. This is a security measure. But Form::Input() calls prep_value(), which also calls Security::htmlentities(), causing the value to be encoded twice. By default PHP's htmlentities() will also double encode. For the Security class, I've commited a fix for this a few days ago that will disable double encoding by default.

    Yes this is exactly true. I tried passing data to view using ->set('var', $var, null) but I had the same results. In the example above I used htmlentities() for demonstration because Form::Input() calls prep_value(), which calls htmlentities() function... Still the strange thing is this only happens on user->profile_fields data which is seralized in the database. If I read and set the same value to a form field, from a non serialized database source then it shows the value OK. This is really strange.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion