[eluser]alucard[/eluser]
Hi guys,
My 'check_against_plan_type' custom callback function is not working.
The other callback functions are working correctly.
The error message that I am getting is:
'Call to a member function set_message() on a non-object in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\codeigniter\application\libraries\my_form_validation.php on line 38'
My callback functions which are in a separate class:
Code:
function compare_cat(){//compare categories - callback function for form validation
if( !$_POST['category1']=="" &&($_POST['category1'] == $_POST['category2'])){
$this->CI->form_validation->set_message('compare_cat','Category 1 and category 2 cannot be the same');
return false;
}
else{
return true;
}
}
function valid_url(){//check if url supplied is valid - callback function for form validation
if(!preg_match('/^((http:\/\/www\.)|(www\.)|(http:\/\/))[a-zA-Z0-9._-]+\.[a-zA-Z.]{2,5}$/', $_POST['link'])){
$this->CI->form_validation->set_message('valid_url',"Enter a valid url, make sure to enter 'http://' first.");
return false;
}
else{
return true;
}
}
function valid_email(){
if(!preg_match( '/^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/', $_POST['email'])){
$this->CI->form_validation->set_message('valid_email',"Enter a valid email");
return false;
}
else{
return true;
}
}
function check_against_plan_type(){
if((isset($_POST['listing_plan_id']) && $_POST['listing_plan_id'] == 3) && str_word_count($_POST['description']) > 100){
$this->CI->form_validaton->set_message('check_against_plan_type', "For the plan you have chosen, description word count cannot be more than 100");
//echo 'more than 50';
//exit;
return false;
}
else{
return true;
}
}
}
This is how I am setting the rules:
Code:
function set_rules(){
//set validation rules
$this->my_form->form_validation->set_rules('category1', $this->field_labels['category1'], "trim|required|xss_clean");
$this->my_form->form_validation->set_rules('category2', $this->field_labels['category2'], "trim|compare_cat|xss_clean");
$this->my_form->form_validation->set_rules('title', $this->field_labels['title'], "trim|required|xss_clean");
$this->my_form->form_validation->set_rules('description', $this->field_labels['description'], "trim|check_against_plan_type|xss_clean");
$this->my_form->form_validation->set_rules('phone', $this->field_labels['phone'], "trim|required|numeric|min_length[10]|max_length[11]");
$this->my_form->form_validation->set_rules('link', $this->field_labels['link'], "trim|required|valid_url|xss_clean");
if(!(isset($_POST['online_only_business'])) && isset($_POST['address_line1'])){
$this->my_form->form_validation->set_rules('address_line1', $this->field_labels['address_line1'], "trim|required|xss_clean");
}
$this->my_form->form_validation->set_rules('address_line2', $this->field_labels['address_line2'], "trim|xss_clean");
if(!(isset($_POST['online_only_business'])) && isset($_POST['city'])){
$this->my_form->form_validation->set_rules('city', $this->field_labels['city'], "trim|required|xss_clean");
}
if(!(isset($_POST['online_only_business'])) && isset($_POST['state'])){
$this->my_form->form_validation->set_rules('state', $this->field_labels['state'], "trim|required|xss_clean");
}
if(!(isset($_POST['online_only_business'])) && isset($_POST['post_code'])){
$this->my_form->form_validation->set_rules('post_code', $this->field_labels['post_code'], "trim|required|numeric|max_length[4]|min_length[4]|xss_clean");
}
$this->my_form->form_validation->set_rules('listing_plan_id', '', "trim|required|xss_clean");
$this->my_form->form_validation->set_rules('email', $this->field_labels['email'], "trim|required|valid_email|xss_clean");
}
}
If anyone can help me out, I'd appreciate it.
Thanks
Alucard