CodeIgniter Forums
How do I use esc() in html form input AND get readable text? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: How do I use esc() in html form input AND get readable text? (/showthread.php?tid=90486)



How do I use esc() in html form input AND get readable text? - objecttothis - 03-25-2024

Problem:
This code
PHP Code:
<?php $sample_text 'The quick brown fox!';
<?= 
form_input ([
 
'name' => 'sample_text',
 
'id' => 'sample_text',
 
'class' => 'form-control input-sm',
 
'value' => esc($sample_text'attr')
]) 
?>

Yields a textbox with the value "The&#x20;quick&#x20;brown&#x20;fox&#x21;"

How can I escape output but still produce readable text in the form? I want "The quick brown fox!" and simple sentences to be plaintext but everything else to be escaped.
Is 'attr' the correct context to use here?


RE: How to use esc() in html form input AND get readable text - kenjis - 03-25-2024

The value of "value" is automatically escaped by form_input().

PHP Code:
'value' => $sample_text 



RE: How to use esc() in html form input AND get readable text - objecttothis - 03-25-2024

(03-25-2024, 06:58 PM)kenjis Wrote: The value of "value" is automatically escaped by form_input().

PHP Code:
'value' => $sample_text 

Thank you. I missed that in the documentation