CodeIgniter Forums

Full Version: Validation of user input
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]veledrom[/eluser]
Hi,

Let's say I have a textarea to collect user inputs. Someone turns up and writes a html code (eg. a table of something, or a img tag with src to naked image, a div with 10000px width and height ....) instead of plain text into it. It wouldn't be nice when I print it on my website. How do I avoid it? Is there any library of helper to deal with it?

Thanks

El Forum

[eluser]BigBad[/eluser]
You could use the php function strip_tags().

El Forum

[eluser]CroNiX[/eluser]
You could even just use strip_tags as a validation rule and it will remove it during validation automatically. Put rules that only "prep" data after any rules that return a boolean (those found under Rule Reference).

El Forum

[eluser]veledrom[/eluser]
Lets say I use this way:

Code:
$this->form_validation->set_rules('first_name', 'first_name', 'trim|required|strip_tags');

Where do I define allowable_tags? For example allow br, p ..... tags