how to make a validation field optional when edit in php codeigniter? -



how to make a validation field optional when edit in php codeigniter? -

i have form add together , update. so, want show field optional when i'm adding has show validation error , when editing same field doesn't inquire validation error. here code

$this->load->library('form_validation'); $this->form_validation->set_rules('title', 'job title', 'trim|required|min_length[5]'); $this->form_validation->set_rules('description', 'job description', 'trim|required'); $this->form_validation->set_rules('qualification', 'job qualification', 'trim|required'); $this->form_validation->set_rules('mskills', 'job mandatory skills', 'trim|required'); $this->form_validation->set_rules('askills', 'job advantage skills', 'trim'); $this->form_validation->set_rules('minexp', 'job min experience', 'trim|required'); $this->form_validation->set_rules('maxexp', 'job max experience', 'trim|required'); $this->form_validation->set_rules('postedon', 'job posted on', 'trim|required'); $this->form_validation->set_rules('postedby', 'job posted by','trim|required'); $this->form_validation->set_rules('salary', 'job salary', 'trim|required'); if($this->form_validation->run() == false) { echo json_encode(array('st'=>0, 'msg' => validation_errors())); }

here want show optional field

$this->form_validation->set_rules('askills', 'job advantage skills', 'trim');

you need create check status edit or add together trigger. create hidden field , check it's edit mode or add together mode , pass value form hidden

<input type='hiddden' name='checkform' value='add/edit'> // value alter on runtime

then check

if($this->input->post('checkform') == 'add') $this->form_validation->set_rules('askills', 'job advantage skills', 'trim|required'); else $this->form_validation->set_rules('askills', 'job advantage skills', 'trim');

php codeigniter

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -