Welcome Guest, Not a member yet? Register   Sign In
form validation question
#1

[eluser]rsmarsha[/eluser]
When submitting a form and running the rules, do I just access the posted variables with $_POST ? I guess what I'm asking is do the validation rules such as xss_clean work on the posted variables?

So $_POST['content'] with an xss_clean validation rule on it, would mean the rule is run and the returned value put back in $_POST['content'] ?

Here is my first effort at handling a form for writing a blog post.

Code:
public function write () {
        $results = $this->blog_model->get_categories();
        $categories = array();
        foreach ($results AS $result) {
            $categories[$result->id] = $result->name;
        }
        $data = array(
            'categories' => $categories
        );

        $this->form_validation->set_rules('title', 'Title', 'required|xss_clean');
        $this->form_validation->set_rules('content', 'Content', 'required|xss_clean');
        if ($this->form_validation->run() === FALSE)
        {
            $this->_view('admin/blog_write_post', $data);
        }
        else
        {
            $post_data = array(
                'title' => ,
                'content' => '',
                'user_id' => '',
                'posted' => '',
                'category' => ''
            );
            $this->blog_model->insert_post($post_data);
            $this->_view('admin/blog_post_submitted', $data);
        }
    }

the post data array is empty at the moment while I check I have the right idea. Does the write method above look ok? I did have a submit and a write method but I figured the above idea should work better. I could be wrong, just thought I'd see what you all thought.


Messages In This Thread
form validation question - by El Forum - 06-09-2011, 01:40 AM
form validation question - by El Forum - 06-09-2011, 09:09 AM
form validation question - by El Forum - 06-09-2011, 09:26 PM
form validation question - by El Forum - 06-09-2011, 10:48 PM
form validation question - by El Forum - 06-10-2011, 01:47 AM
form validation question - by El Forum - 06-10-2011, 08:19 AM
form validation question - by El Forum - 06-13-2011, 02:06 AM
form validation question - by El Forum - 06-13-2011, 07:35 AM
form validation question - by El Forum - 06-13-2011, 11:22 AM
form validation question - by El Forum - 06-14-2011, 01:14 AM
form validation question - by El Forum - 06-14-2011, 01:33 AM
form validation question - by El Forum - 06-15-2011, 09:11 AM
form validation question - by El Forum - 06-15-2011, 10:23 AM
form validation question - by El Forum - 06-16-2011, 03:09 AM



Theme © iAndrew 2016 - Forum software by © MyBB