⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

validate fields according option.



Maicol Ortiz Tello

Maicol Ortiz Tello
  • profile picture
  • Member

Posted 16 November 2014 - 05:11 AM

Hi all, I have a problem I need help.
tenho a form to add an article and a select box at the beginning if it is to indicate whether the article or just an image. good is that based on the choice of the select box depends hide and show some input that's ok, but I need some input validation and other all depends on the option chosen.
[attachment=859:img1.PNG]
 
[attachment=860:img2.PNG]

 


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 16 November 2014 - 10:33 AM

hi there

i will share you this piece of code thats there for validating confirm password if the password is set

 

            $required_if = $this->input->post('new_password') ? '|required' : '' ;
            $validation_check = $this->input->post('new_password') ? '|required|matches[confirm_passwd]' : '' ;
            $crud->set_rules('confirm_passwd', 'New Password', 'trim'. $required_if);
            $crud->set_rules('new_password', 'New Password Again', 'trim'.$validation_check);

 

This might help you understand the same. u might jet go through the same :)


Maicol Ortiz Tello

Maicol Ortiz Tello
  • profile picture
  • Member

Posted 16 November 2014 - 15:14 PM

perfect! I had not thought I did not think they could capture fields with $ this-> input-> post ();

 

my solution ...
    $post=$this->input->post();
    if($post['is_article']==1){
        $crud->required_fields('title','text','is_article','image');
    }else{
       $crud->required_fields('title','is_article','image'); 
    }

Thanks Amit Shah, Greetings from Chile!