[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');
}
}
}