-
hafijul233 Newbie

-
Posts: 7
Threads: 4
Joined: Apr 2020
Reputation:
0
04-22-2020, 12:33 PM
(This post was last modified: 04-22-2020, 12:42 PM by jreklund.)
I am working on recruitment system where different job post has different validation order and list . how i can dynamically change form validation rule group in controller based on form submitted. this is my current approach try for more optimal solution.
PHP Code: //Form validation Rules if (in_array('people_basic', $meta['attributes']) == TRUE) {
$this->form_validation->set_rules('full_name', 'Applicant Name', 'trim|required|max_length[255]|alpha_numeric_spaces'); $this->form_validation->set_rules('father_name', 'Father\'s Name', 'trim|required|max_length[255]|alpha_numeric_spaces'); $this->form_validation->set_rules('mother_name', 'Mother\'s Name', 'trim|required|max_length[255]|alpha_numeric_spaces'); $this->form_validation->set_rules('birth_date', 'Birth Date', 'trim|required|exact_length[10]|regex_match[/^[\d]{4}-[\d]{2}-[\d]{2}$/]'); $this->form_validation->set_rules('place_of_birth', 'Birth Place', 'trim|required|max_length[255]'); $this->form_validation->set_rules('gender', 'Gender', 'required|integer|exact_length[1]'); $this->form_validation->set_rules('nationality', 'Nationality', 'trim|required|integer'); $this->form_validation->set_rules('national_id', 'National ID', 'trim|integer'); $this->form_validation->set_rules('birth_reg_id', 'Birth Registration No.', 'trim|integer'); $this->form_validation->set_rules('passport_id', 'Passport ID', 'trim|alpha_numeric'); $this->form_validation->set_rules('religion', 'Religion', 'trim|required|integer|exact_length[1]'); $this->form_validation->set_rules('marital_status', 'Marital Status', 'trim|required|integer'); $this->form_validation->set_rules('spouse_name', 'Spouse Name', 'trim|max_length[255]|alpha_numeric_spaces'); $this->form_validation->set_rules('quota', 'Quota', 'trim|required|integer');
}
if (in_array('people_present_address', $meta['attributes']) == TRUE) {
$this->form_validation->set_rules('present_care_of', 'Care Of', 'trim|required|max_length[255]|alpha_numeric_spaces'); $this->form_validation->set_rules('present_address', 'Village/Flat ...', 'trim|required|max_length[500]'); $this->form_validation->set_rules('present_district', 'District', 'trim|required|integer'); $this->form_validation->set_rules('present_upazila', 'P.S./ Upazila', 'trim|required|integer'); $this->form_validation->set_rules('present_p_o', 'Post Office', 'trim|required|alpha_numeric_spaces'); $this->form_validation->set_rules('present_p_c', 'Post Code', 'trim|required|integer|exact_length[4]'); }
if (in_array('people_permanent_address', $meta['attributes']) == TRUE) { $this->form_validation->set_rules('permanent_care_of', 'Care Of', 'trim|required|max_length[255]|alpha_numeric_spaces'); $this->form_validation->set_rules('permanent_address', 'Village/Flat ...', 'trim|required|max_length[500]'); $this->form_validation->set_rules('permanent_district', 'District', 'trim|required|integer'); $this->form_validation->set_rules('permanent_upazila', 'P.S./ Upazila', 'trim|required|integer'); $this->form_validation->set_rules('permanent_p_o', 'Post Office', 'trim|required|alpha_numeric_spaces'); $this->form_validation->set_rules('permanent_p_c', 'Post Code', 'trim|required|integer|exact_length[4]'); }
if (in_array('people_basic', $meta['attributes']) == TRUE) {
$this->form_validation->set_rules('mobile_number', 'Mobile Number', 'trim|required|exact_length[11]|regex_match[/^01[\d]{9}$/]'); $this->form_validation->set_rules('confirm_mobile', 'Confirm Mobile', 'trim|required|exact_length[11]|matches[mobile_number]'); $this->form_validation->set_rules('email_address', 'Email Address', 'trim|valid_email');
}
if (in_array('education_five', $meta['attributes']) == TRUE) { $this->form_validation->set_rules('five_school_name', 'School Name', 'trim|required|max_length[255]|alpha_numeric_spaces'); $this->form_validation->set_rules('five_board', 'Board', 'trim|required|integer'); $this->form_validation->set_rules('five_roll', 'Class Roll', 'trim|required|integer'); $this->form_validation->set_rules('five_pass_year', 'Passing Year', 'trim|required|integer|exact_length[4]'); $this->form_validation->set_rules('five_result_type', 'Result Type', 'trim|required|numeric'); $this->form_validation->set_rules('five_gpa_result', 'GPA Result', 'trim|numeric|callback_gpa_checker[five_result_type]'); }
if (in_array('education_eight', $meta['attributes']) == TRUE) { $this->form_validation->set_rules('eight_school_name', 'School Name', 'trim|required|max_length[255]|alpha_numeric_spaces'); $this->form_validation->set_rules('eight_board', 'Board', 'trim|required|integer'); $this->form_validation->set_rules('eight_roll', 'Class Roll', 'trim|required|integer'); $this->form_validation->set_rules('eight_pass_year', 'Passing Year', 'trim|required|integer|exact_length[4]'); $this->form_validation->set_rules('eight_result_type', 'Result Type', 'trim|required|numeric'); $this->form_validation->set_rules('eight_gpa_result', 'GPA Result', 'trim|numeric|callback_gpa_checker[eight_result_type]'); }
-
alihrphrp Newbie

-
Posts: 1
Threads: 0
Joined: Aug 2020
Reputation:
0
(04-22-2020, 12:33 PM)hafijul233 Wrote: I am working on recruitment system where different job post has different validation order and list . how i can dynamically change form validation rule group in controller based on form submitted. this is my current approach try for more optimal solution.
PHP Code: //Form validation Rules if (in_array('people_basic', $meta['attributes']) == TRUE) {
$this->form_validation->set_rules('full_name', 'Applicant Name', 'trim|required|max_length[255]|alpha_numeric_spaces'); $this->form_validation->set_rules('father_name', 'Father\'s Name', 'trim|required|max_length[255]|alpha_numeric_spaces'); $this->form_validation->set_rules('mother_name', 'Mother\'s Name', 'trim|required|max_length[255]|alpha_numeric_spaces'); $this->form_validation->set_rules('birth_date', 'Birth Date', 'trim|required|exact_length[10]|regex_match[/^[\d]{4}-[\d]{2}-[\d]{2}$/]'); $this->form_validation->set_rules('place_of_birth', 'Birth Place', 'trim|required|max_length[255]'); $this->form_validation->set_rules('gender', 'Gender', 'required|integer|exact_length[1]'); $this->form_validation->set_rules('nationality', 'Nationality', 'trim|required|integer'); $this->form_validation->set_rules('national_id', 'National ID', 'trim|integer'); $this->form_validation->set_rules('birth_reg_id', 'Birth Registration No.', 'trim|integer'); $this->form_validation->set_rules('passport_id', 'Passport ID', 'trim|alpha_numeric'); $this->form_validation->set_rules('religion', 'Religion', 'trim|required|integer|exact_length[1]'); $this->form_validation->set_rules('marital_status', 'Marital Status', 'trim|required|integer'); $this->form_validation->set_rules('spouse_name', 'Spouse Name', 'trim|max_length[255]|alpha_numeric_spaces'); $this->form_validation->set_rules('quota', 'Quota', 'trim|required|integer');
}
if (in_array('people_present_address', $meta['attributes']) == TRUE) {
$this->form_validation->set_rules('present_care_of', 'Care Of', 'trim|required|max_length[255]|alpha_numeric_spaces'); $this->form_validation->set_rules('present_address', 'Village/Flat ...', 'trim|required|max_length[500]'); $this->form_validation->set_rules('present_district', 'District', 'trim|required|integer'); $this->form_validation->set_rules('present_upazila', 'P.S./ Upazila', 'trim|required|integer'); $this->form_validation->set_rules('present_p_o', 'Post Office', 'trim|required|alpha_numeric_spaces'); $this->form_validation->set_rules('present_p_c', 'Post Code', 'trim|required|integer|exact_length[4]'); }
if (in_array('people_permanent_address', $meta['attributes']) == TRUE) { $this->form_validation->set_rules('permanent_care_of', 'Care Of', 'trim|required|max_length[255]|alpha_numeric_spaces'); $this->form_validation->set_rules('permanent_address', 'Village/Flat ...', 'trim|required|max_length[500]'); $this->form_validation->set_rules('permanent_district', 'District', 'trim|required|integer'); $this->form_validation->set_rules('permanent_upazila', 'P.S./ Upazila', 'trim|required|integer'); $this->form_validation->set_rules('permanent_p_o', 'Post Office', 'trim|required|alpha_numeric_spaces'); $this->form_validation->set_rules('permanent_p_c', 'Post Code', 'trim|required|integer|exact_length[4]'); }
if (in_array('people_basic', $meta['attributes']) == TRUE) {
$this->form_validation->set_rules('mobile_number', 'Mobile Number', 'trim|required|exact_length[11]|regex_match[/^01[\d]{9}$/]'); $this->form_validation->set_rules('confirm_mobile', 'Confirm Mobile', 'trim|required|exact_length[11]|matches[mobile_number]'); $this->form_validation->set_rules('email_address', 'Email Address', 'trim|valid_email');
}
if (in_array('education_five', $meta['attributes']) == TRUE) { $this->form_validation->set_rules('five_school_name', 'School Name', 'trim|required|max_length[255]|alpha_numeric_spaces'); $this->form_validation->set_rules('five_board', 'Board', 'trim|required|integer'); $this->form_validation->set_rules('five_roll', 'Class Roll', 'trim|required|integer'); $this->form_validation->set_rules('five_pass_year', 'Passing Year', 'trim|required|integer|exact_length[4]'); $this->form_validation->set_rules('five_result_type', 'Result Type', 'trim|required|numeric'); $this->form_validation->set_rules('five_gpa_result', 'GPA Result', 'trim|numeric|callback_gpa_checker[five_result_type]'); }
if (in_array('education_eight', $meta['attributes']) == TRUE) { $this->form_validation->set_rules('eight_school_name', 'School Name', 'trim|required|max_length[255]|alpha_numeric_spaces'); $this->form_validation->set_rules('eight_board', 'Board', 'trim|required|integer'); $this->form_validation->set_rules('eight_roll', 'Class Roll', 'trim|required|integer'); $this->form_validation->set_rules('eight_pass_year', 'Passing Year', 'trim|required|integer|exact_length[4]'); $this->form_validation->set_rules('eight_result_type', 'Result Type', 'trim|required|numeric'); $this->form_validation->set_rules('eight_gpa_result', 'GPA Result', 'trim|numeric|callback_gpa_checker[eight_result_type]'); }
|