CodeIgniter Forums
problem with html tags from forms - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: problem with html tags from forms (/showthread.php?tid=4530)



problem with html tags from forms - El Forum - 11-30-2007

[eluser]Zerg[/eluser]
I've got very weird problem with CI. I have form with inputs, textareas inside.
When I try to display some data from form everything looks fine. The error appear
when any html tag is in input or textarea for example
Code:
<b>bold</b>
.

After submit controller displays nothing. Literally nothing - no errors, no data from form and even
<code>echo 'Hello World' </code> doesn't work. htmlspecialchars(), striptags() etc don't work.

I'm using php in 5.2.5 version. TIA.


problem with html tags from forms - El Forum - 11-30-2007

[eluser]Majd Taby[/eluser]
Are you saving the data in the database? or is this happening when you're repopulating the form? some code would be great. My first guess is that the data isn't getting into your db.


problem with html tags from forms - El Forum - 12-01-2007

[eluser]Zerg[/eluser]
Yes, I'm trying to save data in the database, but apparently problem is in getting values from form. Everything (saving in the database too) when I don't type html tags in form. Maybe as you suggest some code would help

The view:
Code:
&lt;?php
$this->load->helper('form');
echo form_open('add');
?&gt;
<div class="error">
  &lt;?=$this->validation->error_string;?&gt;
</div>
Title:
&lt;input type="text" name="title" value="&lt;?=$this-&gt;input->post('title')?&gt;"/>
//Description: &lt;textarea name="description"&gt;&lt;?=$this->input->post('description')?&gt;&lt;/textarea&gt;
Tags (seperate by comma): &lt;input type="text" name="tags" value="&lt;?=$this-&gt;input->post('tags')?&gt;"/>
&lt;?php
echo form_submit('submit', 'Add!');
echo form_close(); ?&gt;

The controller:
Code:
// [...] part of class Scripts
function addnew() {
    if($this->input->server('REQUEST_METHOD') == 'POST') {  
        $rules['title']='trim|required|min_length[8]';
        $rules['description']='trim|required|min_length[15]';
        $rules['tags']='trim|required|min_length[2]';
      
        $this->validation->set_rules($rules);  
        
        if($this->validation->run() == true) {
          // model name is scr  
          $result = $this->scr->add(array(
          'title' => $this->input->post('title'),
          'description' => $this->input->post('description'),  
          'tags' => $this->input->post('tags')  
          ));  
          if($result) {
            redirect('scripts/view/'.$result, 'location');            
          } else {
            // todo: redirect to error page
            echo 'Not logged in!';      
          }
        } else {    
          $this->response['content'] = $this->load->view('scr/new_script.php', '', True);
          $this->load->view('index.php', $this->response);  
        }
    } else {
      $this->response['content'] = $this->load->view('scr/new_script.php', '', True);
      $this->load->view('index.php', $this->response);  
    }  
  }
[...]

And the model:
Code:
[...] part of class Scr
function add($array) {
    // tag
    $tags = $this->tags->getTagsFromInput($array['tags']);
    unset($array['tags']);
    if($this->session->userdata('logged')) {
      $array['user_id'] = $this->session->userdata('id');
      $this->db->insert('scripts', $array);  
      $id = $this->db->insert_id();
      foreach($tags as $value) {
        $this->tags->addTag($id, $value);        
      }      
      return $id;      
    }
    return false;
  }
// [...]

It can't be simpler, I suppose.


problem with html tags from forms - El Forum - 12-01-2007

[eluser]xwero[/eluser]
Just a guess but have you put the global xss to true?


problem with html tags from forms - El Forum - 12-01-2007

[eluser]Zerg[/eluser]
xwero: Yes i put it to true.