Welcome Guest, Not a member yet? Register   Sign In
CI-Validation + Recaptcha
#2

[eluser]awpti[/eluser]
Wow, was this a tough one to wrap my head around, but I finally got the logic.

Code posted below, so if anyone else ever runs into validation+recaptcha!

Code:
function index()
        {
                $rules = array
                (
                        'location'      => 'required|xss_clean',
                        'company'       => 'xss_clean',
                        'email'         => 'required|valid_email',
                        'job_title'     => 'required|xss_clean',
                        'description'   => 'required|xss_clean',
                        'to_apply'      => 'required|prep_url|xss_clean',
                        'website'       => 'required|prep_url|xss_clean'
                );

                $fields = array
                (
                        'location'      => 'Location',
                        'company'       => 'Company',
                        'email'         => 'E-Mail',
                        'job_title'     => 'Job Title',
                        'description'   => 'Description',
                        'to_apply'      => 'How to Apply',
                        'website'       => 'Website'
                );
                $this->view->set('error', FALSE);
                $this->validation->set_rules($rules);
                $this->validation->set_fields($fields);

                if ($this->validation->run() == FALSE)
                {
                        $this->view->load('add_job');
                }
                else
                {

                        if ($this->input->post('recaptcha_response_field'))
                        {
                                $resp = recaptcha_check_answer
                                (
                                        '************ PRIVATE KEY **************',
                                        $_SERVER["REMOTE_ADDR"],
                                        $this->input->post('recaptcha_challenge_field'),
                                        $this->input->post('recaptcha_response_field')
                                );

                                if ($resp->is_valid == FALSE) {
                                        $this->view->set('error', $resp->error);
                                        $this->view->load('add_job');
                                } else {
                                        $data = array
                                        (
                                                'location'      => $this->input->post('location'),
                                                'company'       => $this->input->post('company'),
                                                'email'         => $this->input->post('email'),
                                                'job_title'     => $this->input->post('job_title'),
                                                'description'   => $this->input->post('description'),
                                                'to_apply'      => $this->input->post('to_apply'),
                                                'website'       => $this->input->post('website'),
                                                'is_validated'  => 0,
                                                'date_created'  => date('Y-m-d H:i:s'),
                                                'edit_key'      => md5(date('Y-m-d H:i:s').$this->input->post('company'))
                                        );
                                        if($this->addjob->add_job($data) === FALSE)
                                        {
                                                echo 'An error has occured. You should not see this. Sorry.';
                                        }
                                        else
                                        {
                                                redirect('/notices/accepted', 'header');
                                        }
                                }
                        }
                        else
                        {
                                $this->view->load('add_job');
                        }
                }
        }


Messages In This Thread
CI-Validation + Recaptcha - by El Forum - 07-17-2008, 08:31 PM
CI-Validation + Recaptcha - by El Forum - 07-17-2008, 11:26 PM
CI-Validation + Recaptcha - by El Forum - 08-20-2008, 03:54 PM
CI-Validation + Recaptcha - by El Forum - 08-20-2008, 04:22 PM
CI-Validation + Recaptcha - by El Forum - 08-20-2008, 06:41 PM



Theme © iAndrew 2016 - Forum software by © MyBB