Welcome Guest, Not a member yet? Register   Sign In
How to display apostrophe instead of HTML when using set_value default value?
#1

[eluser]benners[/eluser]
It seems when using set_value, if I have an apostrophe in the default value it displays in the input as ' Does anyone know a way around this?

html_entity_decode doesn't seem to help.

Code:
$data = array(
   'name'        => 'title',
   'value'       => set_value('title', html_entity_decode("Who's"))
);
echo form_input($data);

HTML returned
Code:
<input type="text" size="50" maxlength="100" value="Who's" name="0[title]">
#2

[eluser]porquero[/eluser]
Is better way don't encode/decode strings. I recomend you to use utf-8 encoding.

Some tips:

Files must have utf-8 charset with unix(lf)

AND

use html metas:
Code:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

AND

Use Database charsert utf-8.
If you use Mysql: "SET NAMES utf8"


ALSO you can use .htaccess to force default charset:

AddDefaultCharset UTF-8

More info: Search for "UTF-8: The Secret of Character Encoding"
#3

[eluser]benners[/eluser]
It looks like everything is utf8

database.php
Code:
$db['default']['char_set'] = 'utf8';

config.php
Code:
$config['charset'] = 'utf-8';

template_head.php
Code:
<meta http-equiv="content-type" content="text/html; charset=utf-8" />

The apostrophe is only converted when added passed through the set_value function.
#4

[eluser]porquero[/eluser]
So you don't need convert apostrophe to set value. Are you try without html_entity_decode function?

Remember that files charset must be utf-8 encoded too. If you use geany you can see it status bar.
#5

[eluser]Aken[/eluser]
Most form helper functions, including set_value(), utilize the htmlspecialchars() function to make sure that anything that has special meaning to HTML is displayed properly when put back into your forms (which is the purpose of set_value()). For instance, say you wanted to save the entity version of an & sign, which is & - if you loaded that into your HTML without any encoding, it would display as a & symbol, which is how your browser interprets it.

This is normal functionality - I'm not sure why you're trying to undo it. When your form is processed, those characters should not be there - it should go through POST as their encoded versions.
#6

[eluser]benners[/eluser]
I'm pulling in the data from the database into an update form. It shows as a Who's there in the database and in the array I populate with the data, but the input on the update form shows Who's when passed through set_value(). I obviously don't want the users to see it like this.
#7

[eluser]benners[/eluser]
If I comment out line 646 in form_helper.php the apostrophe's display fine in the input.

Line 646: $str = htmlspecialchars($str);

Obviously I don't want to modify system files, so how can I get apostrophes to display correctly when using set_value and form validation?
#8

[eluser]aquary[/eluser]
Value: "Who's"
html_entity_decode() returns Who& #39;s (space added to avoid conversion)
set_value() of the above returns Who& amp;#39;s (space added to avoid conversion)

Sure you will see & amp;#39; instead of '
remove the html_entity_decode(), and everythin will works correctly.
#9

[eluser]benners[/eluser]
Ahh! Stupid mistake. The field name in set_value was not the same as for 'name'. I would have thought this wouldn't show anything or give an error, but it just did something to the apostrophes.

Code:
$data = array(
    'name'        => $i.'[answer_a]',
    'value'       => set_value($i.'answer_a', $quiz[$i]['answer_a']),
  );
echo form_input($data);

Sorry to waste people's time.




Theme © iAndrew 2016 - Forum software by © MyBB