Is it possible that tinymce is escaping things on the clientside for you? Otherwise, it's not clear to me where your problem might be. The 'alert still pops up' doesn't give us much to go on. :) Could you be more specific as to where your problem lies? Is the data getting saved to the database as you'd expect? Posting your view / controller code may help too.
Help with Input sanitization
I am using a form with TinyMce editor. I'm trying to allow
<p> <div> <em> <strong> <ul> <ol> <li>
elements while at the same time removing < script > tags. For some reason when I get the input from the form it is already escaped and looks like this:
<p>hello world</p>
<p>< script > alert('hi'); < /script > </p>
<p></p>
<p></p>
I'm setting this data to a dirtyInput array and running it through this foreach loop:
//validate the input based on Note.php rules
$validation = Validator::make($dirtyInput = Input::except('mbo_appointment_id'), Quickernotes\Note::$rules);
if($validation->fails())
{
return \Redirect::back()->withInput()->withErrors($validation);
}
//strip out not allowed tags
$input = [];
foreach($dirtyInput as $key => $val){
$input += [$key => strip_tags($val, '<p> <div> <ol> <ul> <li> <strong> <em>') ];
}
After this loop I save the input to the database. When I pass this data back to the view the alert still pop's up on the screen! I'm also using the {{{triple curly braces}}} in blade templates.
What am I doing wrong?
The problem as i see strip_tags don't delete "script" from your code, because it's already converted to entities,
What i meant is to create a function that will convert entities to tags and then apply the strip_tags function.
function my_custom_function($dirtyInput ){
$tags = html_entity_decode($dirtyInput);
return strip_tags($tags, '<p> <div> <ol> <ul> <li> <strong> <em>');
}
so that you can use it like this :
$input = [];
foreach($dirtyInput as $key => $val){
$input += [$key => my_custom_function($val) ];
}
Please or to participate in this conversation.