⚠ 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

Set rules with getState() not working



aneesh
  • profile picture
  • Member

Posted 24 October 2013 - 07:19 AM

Hi guys,

 

In my application I am using the grocery crud to add a user . I am experiencing a problem on this.  The set_rules and required fields are not working when I am clicking on the save button. Before that it is rendering fine and displaying the required filed labels with * symbol. 

Here is my code

 

public function create_user(){
  $crud = new grocery_CRUD();
  $crud->set_table('user')
       ->set_subject('New User')
       ->columns('user_name','password','id_user_role','pubid') 
       ->add_fields('user_name','password','id_user_role','pubid')
      ->edit_fields('user_name','password','id_user_role','pubid') 
      ->set_relation('id_user_role','user_role','name')        
      ->display_as('id_user_role','Role');
  $state_code = $crud->getState();
  if($state_code == 'edit') {
    $crud->required_fields('password','id_user_role');
    $crud->set_rules('user_name','Username', 'trim|required|xss_clean'); 
  }elseif($state_code == 'add'){
    $crud->required_fields('user_name','password','id_user_role'); 
    $crud->set_rules('user_name','Username', 'trim|required|xss_clean|is_unique[user.user_name]'  );
 }
 $output = $crud->render(); 
 $data['gcrud'] = $output;
 $data['content'] = 'admin/create_user_view'; 
 $this->load->view('template',$data);
}

please help me to fix this. 

 


aneesh
  • profile picture
  • Member

Posted 24 October 2013 - 09:44 AM

Hi 

Got solution for this 

 

if(($state_code == 'edit') OR ($state_code == 'update_validation')) {
     $crud->required_fields('password','id_user_role'); 
}elseif(($state_code == 'add') OR ($state_code == 'insert_validation')){ 
     $crud->set_rules('user_name','Username', 'trim|required|xss_clean|is_unique[user.user_name]');
    $crud->required_fields('user_name','password','id_user_role');
}

engr zardari
  • profile picture
  • Member

Posted 24 October 2013 - 14:20 PM

click here this may also help you..

 

http://www.grocerycrud.com/documentation/options_functions/getState