Welcome Guest, Not a member yet? Register   Sign In
problem with html tags from forms
#1

[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.
#2

[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.
#3

[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.
#4

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

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




Theme © iAndrew 2016 - Forum software by © MyBB