Welcome Guest, Not a member yet? Register   Sign In
Form validation on page with DB call
#1

[eluser]Unknown[/eluser]
Just wanted to double-check. This seems like the most logical way, but I thought I'd ask anyway:

If I wanted to validate a form on page that does a DB call, is this the best way? The form posts to itself.

Code:
function read_messages(){
    if ($_POST) {
        # VALIDATE FORM IF POSTED
        $this->load->library('form_validation');
        $this->form_validation->set_rules('name', 'Name', 'trim|required');
        if ($this->form_validation->run() == TRUE) {$this->create_message();}
    }
    
    # GET MESSAGES AND OUTPUT TO BROWSER
    $this->load->model('message_model');
    $data['messages'] = $this->message_model->read_messages($some_var);
    $data['main_content'] = 'user_messages';
    $this->load->view('includes/template', $data);
}


Previously I was submitting to another page, and that was stupid, b/c when form validation failed I had code duplication.




Theme © iAndrew 2016 - Forum software by © MyBB