Welcome Guest, Not a member yet? Register   Sign In
Use HTML in error message
#1

(This post was last modified: 02-28-2024, 03:33 AM by groovebird.)

Hi,

i define my error messages in a language file:

PHP Code:
return [
    
'required' => 'Please fill in the {field} field',
]; 

Is it possible to use HTML in this message

PHP Code:
return [
    
'required' => 'Please fill in the <i>{field}</i> field',
]; 

Now the html tag will be displayed as text
Reply
#2

In my local CI 4.4.6 enviroment the following text is displayed with italic:
'bankDetails'  => 'These are the <i>Bank details</i>',
Otherwise, try:
echo html_entity_decode(lang('Dashboard.bankDetails'));
Reply
#3

Hi,

in my template i use echo $validation->showError('field'). Where should i place the htm_entity_decode?
Reply
#4

Try this, you might be lucky, haven't tested it myself:
PHP Code:
html_entity_decode($validation->showError('field')); 
Reply
#5

(This post was last modified: 02-28-2024, 07:12 AM by groovebird.)

I wonder why it is working on your installation and not in my installation. Are the validation language files handled different than other language files?

btw: your solution is working
Reply
#6

I didn't test it with a validation language file, but in a regular language file.
I am not sure if you have seen this:
https://codeigniter4.github.io/userguide...ion-labels
If your problem is solved by using the proposed solution, please mark the thread as solved.
Reply
#7

Hi, could you test it with a validation file? Your solution is working, but i have to adjust all my templates. If it is working with a regular language file why not with with validation?
Reply
#8

Warning
If you get the error messages with getErrors() or getError(), the messages are not HTML escaped. If you use user input data like ({value}) to make the error message, it might contain HTML tags. If you don’t escape the messages before displaying them, XSS attacks are possible.
https://codeigniter4.github.io/CodeIgnit...r-messages
Reply
#9

Ok, i understand. I thought there is only the {field} placeholder which is no user input
Reply




Theme © iAndrew 2016 - Forum software by © MyBB