Welcome Guest, Not a member yet? Register   Sign In
How do I use esc() in html form input AND get readable text?
#1

(This post was last modified: 03-25-2024, 06:49 PM by objecttothis. Edit Reason: clarity )

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?
Reply
#2

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

PHP Code:
'value' => $sample_text 
Reply
#3

(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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB