Welcome Guest, Not a member yet? Register   Sign In
simple error question
#10

[eluser]Seppo[/eluser]
The first time should be after setting the fields and the rules... That´s why it can´t find the fields errors: they aren´t setted.
The second time is also calling the view, cause it is failing the validation...
A simplier way to do it

Code:
function index()
    {
        // Load the helpers for URLs and forms
        $this->load->helper('url');
        $this->load->helper('form');
        
        // Load the library for validation
        $this->load->library('validation');    
        $this->load->library('email');    
        
        // Set page information and load the view file
        $data['title'] = "Contact";
        
        // Set the validation rules
        $rules['name'] = "required|trim";
        $rules['email'] = "required|trim";
        $rules['subject'] = "";
        $rules['message'] = "required|trim";
        $this->validation->set_rules($rules);
        
        // Set the fields for all of the input fields in case someone enters something incorrectly
        $fields['name'] = "Name";
        $fields['email'] = "Email";
        $fields['subject'] = "Subject";
        $fields['message'] = "Message";
        $this->validation->set_fields($fields);
        
        // Run the validation
        // If the validation is successful, send the email
        if($this->validation->run() == TRUE)
        {
            $this->email->from($this->validation->email, $this->validation->name);
            $this->email->to('[email protected]');
            $this->email->subject($this->input->post('subject'));
            $this->email->message($this->validation->message);
            
            $this->email->send();
            
            echo $this->email->print_debugger();
        } else {
             // and if it's not successful (or the form is not sent), return them to the registration page
            $this->load->view('contact_view', $data);
        }
    }


Messages In This Thread
simple error question - by El Forum - 01-15-2008, 08:56 AM
simple error question - by El Forum - 01-15-2008, 10:38 AM
simple error question - by El Forum - 01-23-2008, 07:20 PM
simple error question - by El Forum - 01-23-2008, 09:10 PM
simple error question - by El Forum - 01-23-2008, 09:21 PM
simple error question - by El Forum - 01-23-2008, 09:23 PM
simple error question - by El Forum - 01-23-2008, 09:27 PM
simple error question - by El Forum - 01-23-2008, 09:31 PM
simple error question - by El Forum - 01-23-2008, 09:33 PM
simple error question - by El Forum - 01-23-2008, 09:39 PM
simple error question - by El Forum - 01-23-2008, 09:49 PM



Theme © iAndrew 2016 - Forum software by © MyBB