Welcome Guest, Not a member yet? Register   Sign In
problem with single quote in input field
#1

Hello,

I have this value in database : test'test

When I try to display the text in a field I get this in the input field : test'test

If I display my variable in the html flux i get : test'test width no problem.

My code :

echo $projets['mo'].'<br>'; // display test'test
$field=array('type'=>'text', 'name'=>'mo','value'=>set_value('mo',$projets['mo']), 'size'=>'64','maxsize'=>'255');
echo form_input($field); // display test'test

Please help,
Reply
#2

Are you expecting a problem? What is the problem? Please clarify.
Reply
#3

I think this may help you

http://php.net/manual/en/function.stripslashes.php
God Bless CI Contributors Smile
Reply
#4

(06-16-2017, 10:26 AM)skunkbad Wrote: Are you expecting a problem? What is the problem? Please clarify.




If fact if I use form_input() it's not working. I get test'test in the input form
If I not use form input I get the correct text in my input field test'test

exemple :

I can replace this
$a="test'test";
$field=array('type'=>'text', 'name'=>'test','value'=>set_value($a), 'size'=>'64','maxsize'=>'255');
echo form_input($field);
By
$a="test'test";
$b=set_value('test',$a);
echo '<input type="text" name="test" value="'.$b.'" size="64" maxsize="255">';
And it's working,

But why I can't use form_input(); it's a bug ?
Reply
#5

It's the combination of form_input and set_value. Both functions "escape" the value.
You can turn off html escaping in set_value, by adding a third parameter:
PHP Code:
set_value('mo',$projets['mo'],FALSE
See if that does the trick.
Otherwise, build the input field with plain html. Then it's possible to use set_value for repopulating the field after form validation.

PHP Code:
<input type="text" name="test" value="<?= set_value('test','default_value');?>" size=64 maxlength=255 /> 
Reply
#6

(06-16-2017, 11:27 PM)Wouter60 Wrote: It's the combination of form_input and set_value. Both functions "escape" the value.
You can turn off html escaping in set_value, by adding a third parameter:
PHP Code:
set_value('mo',$projets['mo'],FALSE
See if that does the trick.
Otherwise, build the input field with plain html. Then it's possible to use set_value for repopulating the field after form validation.

PHP Code:
<input type="text" name="test" value="<?= set_value('test','default_value');?>" size=64 maxlength=255 /> 

Hello, it's working by adding the false parameter, thank's for all.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB