Welcome Guest, Not a member yet? Register   Sign In
Strip HTML tag
#1

[eluser]Mithun[/eluser]
What is the best method to strip htnl tags from the input?

How can i remove the HTML tags while validating the input
$this->form_validation->set_rules('description', 'Description', 'trim|xss_clean');

Do I need to add custom call back method to validation rules?
#2

[eluser]Sbioko[/eluser]
No, you don't need to create a callback. To strip all HTML tags strip_tags function will help you. Something like this:
Code:
$clean = strip_tags($this->input->post('description'));
#3

[eluser]Mithun[/eluser]
Thanjk you Sbioko,

i wand something while form validation
#4

[eluser]Sbioko[/eluser]
Oh, my mistake. Yeah, you need to create a callback. Sorry ;-) Call it for example strip_html_tags.
Code:
public function strip_html_tags($s) {
    return strip_tags($s);
}
#5

[eluser]Mithun[/eluser]
Again problem comes here, call back function need to be return true or false not the stripped string

I have a call back function
Code:
public function html_clean($s) {
    return strip_tags($s);
}

and i use it like
Code:
$this->form_validation->set_rules('customer', 'Customer', 'trim|required|callback_html_clean|xss_clean');
#6

[eluser]rogierb[/eluser]
try something like :
Code:
$this->form_validation->set_rules('customer', 'Customer', 'trim|required|callback_html_clean['customer']|xss_clean');
public function html_clean($s, $v) {

    $_POST[$v] = strip_tags($s);
    return true;
}
#7

[eluser]Mithun[/eluser]
Is it better to have a MY_Contoller method ?

Code:
class MY_Contoller
{
  MY_Contoller()
  {
    foreach($_POST as $k=>$v)
    {
      $_POST[$k] = strip_tags($_POST[$k]);
    }
  }
}
#8

[eluser]Sbioko[/eluser]
Guys, are you kidding? What are $_POST or MY_Controller. Did you try my solution? Before say or ask something, you should see in the user guide.
#9

[eluser]rogierb[/eluser]
Hey, they guy wanted a true or false solution, I gave him that.

Your solution does the trick, I know that. Don't get mad at me... Sick
#10

[eluser]Sbioko[/eluser]
I'm not mad. As I understood, he wants to cut out all the HTML tags, not validate(TRUE/FALSE). I gave him a solution, but he didn't try it. Maybe I misunderstand something, because English is a foreign language for me.




Theme © iAndrew 2016 - Forum software by © MyBB