application/controllers/Pages.php
/**
     * Method to save contact form data.
     * 
     * @return void
     */
Method to save contact form data.

@return void
Method to save contact form data . @return void
public function contactSubmit()
    {
        $data['title'] = 'Contact';
        $this->form_validation->set_rules(
            'name', 'Name', 'trim|required'
        );
        $this->form_validation->set_rules(
            'email', 'Email', 'trim|required|valid_email'
        );
        $this->form_validation->set_rules(
            'mobile', 'Mobile', 'trim|required|regex_match[/^[0-9]{10}$/]'
        );
        $this->form_validation->set_rules(
            'message', 'Message', 'trim|required'
        );
        if ($this->form_validation->run() == false) {
            $response = array(
                'status'=>'error',
                'message' => validation_errors()
            );
        } else {
            $contactData = array(
                'name'=>$this->input->post('name', true),
                'email'=>$this->input->post('email', true),
                'mobile'=>$this->input->post('mobile', true),
                'message'=>$this->input->post('message', true)
            );
            $this->PageModel->insertContactData($contactData);
            $response = array(
                'status'=>'success',
                'message' => 'Message sent <strong>successfully!</strong>'
            );
        }
        $this->output
            ->set_content_type('application/json')
            ->set_output(json_encode($response));
    }
public function contactSubmit ( ) { $ data [ 'title' ] = 'Contact' ; $ this -> form_validation -> set_rules ( 'name' , 'Name' , 'trim|required' ) ; $ this -> form_validation -> set_rules ( 'email' , 'Email' , 'trim|required|valid_email' ) ; $ this -> form_validation -> set_rules ( 'mobile' , 'Mobile' , 'trim|required|regex_match[/^[0-9]{10}$/]' ) ; $ this -> form_validation -> set_rules ( 'message' , 'Message' , 'trim|required' ) ; if ( $ this -> form_validation -> run ( ) == false ) { $ response = array ( 'status' => 'error' , 'message' => validation_errors ( ) ) ; } else { $ contactData = array ( 'name' => $ this -> input -> post ( 'name' , true ) , 'email' => $ this -> input -> post ( 'email' , true ) , 'mobile' => $ this -> input -> post ( 'mobile' , true ) , 'message' => $ this -> input -> post ( 'message' , true ) ) ; $ this -> PageModel -> insertContactData ( $ contactData ) ; $ response = array ( 'status' => 'success' , 'message' => 'Message sent <strong>successfully!</strong>' ) ; } $ this -> output -> set_content_type ( 'application/json' ) -> set_output ( json_encode ( $ response ) ) ; }
Method to save contact form data.
Method to save contact form data .
// $this->form_validation->set_error_delimiters( //     '<div class="invalid-feedback">', '</div>' // );