MERGE_TEST_FORM_VALIDATIONS_DONE
This commit is contained in:
commit
bc8a11aae5
@ -2689,7 +2689,7 @@ class ClientController extends AdminController
|
|||||||
'errors' => ['required' => 'Please select a Client Branch.']
|
'errors' => ['required' => 'Please select a Client Branch.']
|
||||||
],
|
],
|
||||||
'policy_type_id' => [
|
'policy_type_id' => [
|
||||||
'rules' => 'required|is_natural_no_zero',
|
'rules' => ['required', 'is_natural_no_zero'],
|
||||||
'errors' => [
|
'errors' => [
|
||||||
'required' => 'Policy Type is required.',
|
'required' => 'Policy Type is required.',
|
||||||
'is_natural_no_zero' => 'Please select a valid Policy Type.'
|
'is_natural_no_zero' => 'Please select a valid Policy Type.'
|
||||||
@ -2707,11 +2707,16 @@ class ClientController extends AdminController
|
|||||||
'rules' => ['required', 'regex_match[/^[a-zA-Z0-9\s_\-\/\\\]+$/]'],
|
'rules' => ['required', 'regex_match[/^[a-zA-Z0-9\s_\-\/\\\]+$/]'],
|
||||||
'errors' => [
|
'errors' => [
|
||||||
'required' => 'Policy No is required.',
|
'required' => 'Policy No is required.',
|
||||||
'regex_match' => 'Policy No Only letters, numbers, spaces, underscores, hyphens, forward slashes, and backslashes are allowed.'
|
'regex_match' => 'Invalid characters in Policy No.'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'gst' => [
|
'gst' => [
|
||||||
'rules' => 'required|numeric|greater_than_equal_to[0]|less_than_equal_to[100]',
|
'rules' => [
|
||||||
|
'required',
|
||||||
|
'numeric',
|
||||||
|
'greater_than_equal_to[0]',
|
||||||
|
'less_than_equal_to[100]'
|
||||||
|
],
|
||||||
'errors' => [
|
'errors' => [
|
||||||
'required' => 'GST percentage is required.',
|
'required' => 'GST percentage is required.',
|
||||||
'numeric' => 'GST must be a valid number.',
|
'numeric' => 'GST must be a valid number.',
|
||||||
@ -2735,16 +2740,31 @@ class ClientController extends AdminController
|
|||||||
'rules' => 'permit_empty'
|
'rules' => 'permit_empty'
|
||||||
],
|
],
|
||||||
'disclaimer' => [
|
'disclaimer' => [
|
||||||
'rules' => 'permit_empty|string|min_length[5]',
|
'rules' => ['permit_empty', 'string', 'min_length[5]'],
|
||||||
'errors' => ['min_length' => 'Disclaimer should be at least 5 characters long if provided.']
|
'errors' => ['min_length' => 'Disclaimer should be at least 5 characters long if provided.']
|
||||||
],
|
],
|
||||||
|
|
||||||
// --- CHECKBOXES (Permit Empty) ---
|
|
||||||
'enrolment_visibility' => ['rules' => 'permit_empty'],
|
'enrolment_visibility' => ['rules' => 'permit_empty'],
|
||||||
'is_lgbtq' => ['rules' => 'permit_empty']
|
'is_lgbtq' => ['rules' => 'permit_empty']
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!$this->validate($rules)) {
|
// 2. Run the initial validation
|
||||||
|
$isValid = $this->validate($rules);
|
||||||
|
|
||||||
|
// 3. Perform manual date comparison
|
||||||
|
$start = $this->request->getPost('policy_start_date');
|
||||||
|
$end = $this->request->getPost('policy_end_date');
|
||||||
|
|
||||||
|
$startDate = change_date_format($start ?? null, 'd-m-Y', 'Y-m-d') ?? null;
|
||||||
|
$endDate = change_date_format($end ?? null, 'd-m-Y', 'Y-m-d') ?? null;
|
||||||
|
|
||||||
|
if ($startDate && $endDate && ($endDate < $startDate)) {
|
||||||
|
// Manually push the error into the validator
|
||||||
|
$this->validator->setError('policy_end_date', 'Policy start and end date are mismatched (End date cannot be before Start date).');
|
||||||
|
$isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Check final status
|
||||||
|
if (!$isValid) {
|
||||||
return $this->response->setStatusCode(400)->setJSON([
|
return $this->response->setStatusCode(400)->setJSON([
|
||||||
'status' => false,
|
'status' => false,
|
||||||
'message' => 'Input validation failed',
|
'message' => 'Input validation failed',
|
||||||
@ -2851,13 +2871,12 @@ class ClientController extends AdminController
|
|||||||
public function editClientPolicy()
|
public function editClientPolicy()
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
// --- BASIC SELECTS (Required) ---
|
|
||||||
'client_branch_id' => [
|
'client_branch_id' => [
|
||||||
'rules' => 'required',
|
'rules' => 'required',
|
||||||
'errors' => ['required' => 'Please select a Client Branch.']
|
'errors' => ['required' => 'Please select a Client Branch.']
|
||||||
],
|
],
|
||||||
'policy_type_id' => [
|
'policy_type_id' => [
|
||||||
'rules' => 'required|is_natural_no_zero',
|
'rules' => ['required', 'is_natural_no_zero'],
|
||||||
'errors' => [
|
'errors' => [
|
||||||
'required' => 'Policy Type is required.',
|
'required' => 'Policy Type is required.',
|
||||||
'is_natural_no_zero' => 'Please select a valid Policy Type.'
|
'is_natural_no_zero' => 'Please select a valid Policy Type.'
|
||||||
@ -2871,17 +2890,20 @@ class ClientController extends AdminController
|
|||||||
'rules' => 'required',
|
'rules' => 'required',
|
||||||
'errors' => ['required' => 'Please select a TPA.']
|
'errors' => ['required' => 'Please select a TPA.']
|
||||||
],
|
],
|
||||||
|
|
||||||
// --- TEXT FIELDS (Required & Specific Format) ---
|
|
||||||
'policy_no' => [
|
'policy_no' => [
|
||||||
'rules' => 'required|regex_match[/^[a-zA-Z0-9\s_\-\/\\\]+$/]',
|
'rules' => ['required', 'regex_match[/^[a-zA-Z0-9\s_\-\/\\\]+$/]'],
|
||||||
'errors' => [
|
'errors' => [
|
||||||
'required' => 'This field is required.',
|
'required' => 'Policy No is required.',
|
||||||
'regex_match' => 'Only letters, numbers, spaces, _, -, /, and \ are allowed.'
|
'regex_match' => 'Invalid characters in Policy No.'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'gst' => [
|
'gst' => [
|
||||||
'rules' => 'required|numeric|greater_than_equal_to[0]|less_than_equal_to[100]',
|
'rules' => [
|
||||||
|
'required',
|
||||||
|
'numeric',
|
||||||
|
'greater_than_equal_to[0]',
|
||||||
|
'less_than_equal_to[100]'
|
||||||
|
],
|
||||||
'errors' => [
|
'errors' => [
|
||||||
'required' => 'GST percentage is required.',
|
'required' => 'GST percentage is required.',
|
||||||
'numeric' => 'GST must be a valid number.',
|
'numeric' => 'GST must be a valid number.',
|
||||||
@ -2889,47 +2911,47 @@ class ClientController extends AdminController
|
|||||||
'less_than_equal_to' => 'GST percentage cannot exceed 100%.'
|
'less_than_equal_to' => 'GST percentage cannot exceed 100%.'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
|
||||||
// --- DATE FIELDS (Required) ---
|
|
||||||
'policy_start_date' => [
|
'policy_start_date' => [
|
||||||
'rules' => 'required|valid_date',
|
'rules' => 'required',
|
||||||
'errors' => [
|
'errors' => ['required' => 'Start date is required.']
|
||||||
'required' => 'Start date is required.',
|
|
||||||
'valid_date' => 'Enter a valid date format (YYYY-MM-DD).'
|
|
||||||
]
|
|
||||||
],
|
],
|
||||||
'policy_end_date' => [
|
'policy_end_date' => [
|
||||||
'rules' => 'required|valid_date',
|
'rules' => 'required',
|
||||||
'errors' => [
|
'errors' => ['required' => 'End date is required.']
|
||||||
'required' => 'End date is required.',
|
|
||||||
'valid_date' => 'Enter a valid date format (YYYY-MM-DD).'
|
|
||||||
]
|
|
||||||
],
|
|
||||||
|
|
||||||
// --- PERMIT EMPTY FIELDS (Optional) ---
|
|
||||||
'base_policy' => [
|
|
||||||
'rules' => 'permit_empty'
|
|
||||||
],
|
],
|
||||||
'wellness_plan_id' => [
|
'wellness_plan_id' => [
|
||||||
'rules' => 'permit_empty|alpha_numeric',
|
'rules' => 'permit_empty|alpha_numeric',
|
||||||
'errors' => [
|
'errors' => ['alpha_numeric' => 'Wellness Plan ID can only contain letters and numbers.']
|
||||||
'alpha_numeric' => 'Wellness Plan ID can only contain letters and numbers (no spaces or special characters).'
|
|
||||||
]
|
|
||||||
],
|
],
|
||||||
'wellness_vendor_id' => [
|
'wellness_vendor_id' => [
|
||||||
'rules' => 'permit_empty'
|
'rules' => 'permit_empty'
|
||||||
],
|
],
|
||||||
'disclaimer' => [
|
'disclaimer' => [
|
||||||
'rules' => 'permit_empty|string|min_length[5]',
|
'rules' => ['permit_empty', 'string', 'min_length[5]'],
|
||||||
'errors' => ['min_length' => 'Disclaimer should be at least 5 characters long if provided.']
|
'errors' => ['min_length' => 'Disclaimer should be at least 5 characters long if provided.']
|
||||||
],
|
],
|
||||||
|
|
||||||
// --- CHECKBOXES (Permit Empty) ---
|
|
||||||
'enrolment_visibility' => ['rules' => 'permit_empty'],
|
'enrolment_visibility' => ['rules' => 'permit_empty'],
|
||||||
'is_lgbtq' => ['rules' => 'permit_empty']
|
'is_lgbtq' => ['rules' => 'permit_empty']
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!$this->validate($rules)) {
|
// 2. Run the initial validation
|
||||||
|
$isValid = $this->validate($rules);
|
||||||
|
|
||||||
|
// 3. Perform manual date comparison
|
||||||
|
$start = $this->request->getPost('policy_start_date');
|
||||||
|
$end = $this->request->getPost('policy_end_date');
|
||||||
|
|
||||||
|
$startDate = change_date_format($start ?? null, 'd-m-Y', 'Y-m-d') ?? null;
|
||||||
|
$endDate = change_date_format($end ?? null, 'd-m-Y', 'Y-m-d') ?? null;
|
||||||
|
|
||||||
|
if ($startDate && $endDate && ($endDate < $startDate)) {
|
||||||
|
// Manually push the error into the validator
|
||||||
|
$this->validator->setError('policy_end_date', 'Policy start and end date are mismatched (End date cannot be before Start date).');
|
||||||
|
$isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Check final status
|
||||||
|
if (!$isValid) {
|
||||||
return $this->response->setStatusCode(400)->setJSON([
|
return $this->response->setStatusCode(400)->setJSON([
|
||||||
'status' => false,
|
'status' => false,
|
||||||
'message' => 'Input validation failed',
|
'message' => 'Input validation failed',
|
||||||
|
|||||||
@ -365,6 +365,7 @@ class LeadsController extends BaseController
|
|||||||
{
|
{
|
||||||
// print_r($this->request->getPost()); die;
|
// print_r($this->request->getPost()); die;
|
||||||
$id = $this->request->getPost('id');
|
$id = $this->request->getPost('id');
|
||||||
|
$postData = $this->request->getPost();
|
||||||
$data = $this->prepareLeadData();
|
$data = $this->prepareLeadData();
|
||||||
$rules = [
|
$rules = [
|
||||||
|
|
||||||
@ -449,6 +450,21 @@ class LeadsController extends BaseController
|
|||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
foreach ($postData as $key => $value) {
|
||||||
|
// Check if the key starts with 'docs_name_'
|
||||||
|
if (strpos($key, 'docs_name_') === 0) {
|
||||||
|
$rules[$key . '.*'] = [
|
||||||
|
'label' => 'Document Name',
|
||||||
|
'rules' => 'permit_empty|regex_match[/^[a-zA-Z0-9_\- ]+$/]',
|
||||||
|
'errors' => [
|
||||||
|
'regex_match' => 'Document Name in {field} can only contain letters, numbers, hyphens, and underscores.'
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// print_r($rules); die;
|
||||||
|
|
||||||
if (isset($data['lead_form_type']) && (int)$data['lead_form_type'] === 2) {
|
if (isset($data['lead_form_type']) && (int)$data['lead_form_type'] === 2) {
|
||||||
$rules['client_type'] = [
|
$rules['client_type'] = [
|
||||||
'rules' => 'required',
|
'rules' => 'required',
|
||||||
@ -793,7 +809,7 @@ class LeadsController extends BaseController
|
|||||||
'source_policy_end_date' => $data['source_policy_end_date'] ?? null,
|
'source_policy_end_date' => $data['source_policy_end_date'] ?? null,
|
||||||
'claim_history' => $data['claim_history'] ?? 0,
|
'claim_history' => $data['claim_history'] ?? 0,
|
||||||
|
|
||||||
'next_reminder_date' => $data['next_reminder_date'] ?? 0,
|
'next_reminder_date' => $data['next_reminder_date'] ?? null,
|
||||||
'is_insurer_auto_mail' => $data['is_insurer_auto_mail'] ?? 0
|
'is_insurer_auto_mail' => $data['is_insurer_auto_mail'] ?? 0
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -1216,37 +1216,51 @@ class TicketController extends BaseController
|
|||||||
'claim_type' => ['label' => 'Claim Type','rules' => 'required',
|
'claim_type' => ['label' => 'Claim Type','rules' => 'required',
|
||||||
'errors' => ['required' => 'Claim Type is required']
|
'errors' => ['required' => 'Claim Type is required']
|
||||||
],
|
],
|
||||||
'hospital_name' => ['label' => 'Hospital Name','rules' => 'required',
|
'hospital_name' => [
|
||||||
'errors' => ['required' => 'Hospital Name is required']
|
'label' => 'Hospital Name',
|
||||||
|
'rules' => 'required|regex_match[/^[a-zA-Z0-9\s\-_.\']+$/]',
|
||||||
|
'errors' => [
|
||||||
|
'required' => 'Hospital Name is required',
|
||||||
|
'regex_match' => 'The {field} can only contain letters, numbers, spaces, dashes, underscores, dots, and apostrophes.'
|
||||||
|
]
|
||||||
],
|
],
|
||||||
'hospital_address' => ['label' => 'Hospital Address','rules' => 'required',
|
'hospital_address' => [
|
||||||
'errors' => ['required' => 'Hospital Address is required']
|
'label' => 'Hospital Address',
|
||||||
|
'rules' => 'permit_empty|regex_match[/^[a-zA-Z0-9\s\-_.,#\/]+$/]',
|
||||||
|
'errors' => [
|
||||||
|
'regex_match' => 'The {field} contains invalid characters (Allowed: letters, numbers, spaces, dashes, commas, dots, # and /).'
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'hospital_state' => [
|
'hospital_state' => [
|
||||||
'label' => 'hospital_State',
|
'label' => 'Hospital State',
|
||||||
'rules' => 'required|regex_match[/^[a-zA-Z\s\-]+$/]',
|
'rules' => 'permit_empty|regex_match[/^[a-zA-Z\s\-]+$/]',
|
||||||
'errors' => [
|
'errors' => [
|
||||||
'required' => 'Hospital State is required.',
|
'regex_match' => 'Hospital State name can only contain letters, spaces, and hyphens.'
|
||||||
'regex_match' => 'Hospital State name can only contain letters, spaces, and hyphens.'
|
]
|
||||||
]
|
],
|
||||||
],
|
'hospital_city' => [
|
||||||
'hospital_city' => [
|
'label' => 'Hospital City', // Added label for consistency
|
||||||
'rules' => 'required|regex_match[/^[a-zA-Z0-9\s\-]+$/]',
|
'rules' => 'permit_empty|regex_match[/^[a-zA-Z\s\-]+$/]',
|
||||||
'errors' => [
|
'errors' => [
|
||||||
'required' => 'Hospital City is required',
|
'regex_match' => 'Hospital City can only contain letters, spaces, and hyphens.'
|
||||||
'regex_match' => 'Hospital City can contain letters, numbers, spaces, and hyphens.'
|
]
|
||||||
]
|
],
|
||||||
],
|
'hospital_pin_code' => [
|
||||||
'hospital_pin_code' => [
|
'label' => 'Hospital Pincode',
|
||||||
'rules' => 'required|numeric|exact_length[6]',
|
'rules' => 'permit_empty|numeric|exact_length[6]',
|
||||||
'errors' => [
|
'errors' => [
|
||||||
'required' => 'Hospital Pincode is required.',
|
'numeric' => 'Hospital Pincode must be digits only.',
|
||||||
'numeric' => 'Hospital Pincode must be digits only.',
|
'exact_length' => 'Hospital Pincode must be exactly 6 digits.'
|
||||||
'exact_length' => 'Hospital Pincode must be exactly 6 digits.'
|
]
|
||||||
]
|
],
|
||||||
],
|
'hospital_phone_no' => [
|
||||||
'hospital_phone_no' => ['label' => 'Hospital Phone','rules' => 'required|numeric|min_length[10]',
|
'label' => 'Hospital Phone',
|
||||||
'errors' => ['min_length' => 'Phone number too short']
|
'rules' => 'permit_empty|numeric|min_length[10]|max_length[15]',
|
||||||
|
'errors' => [
|
||||||
|
'numeric' => 'Phone number must contain only digits.',
|
||||||
|
'min_length' => 'Phone number is too short.',
|
||||||
|
'max_length' => 'Phone number is too long.'
|
||||||
|
]
|
||||||
],
|
],
|
||||||
'doa' => ['label' => 'DOA', 'rules' => 'required',
|
'doa' => ['label' => 'DOA', 'rules' => 'required',
|
||||||
'errors' => ['required' => 'Date of Admission is required']
|
'errors' => ['required' => 'Date of Admission is required']
|
||||||
@ -1551,23 +1565,51 @@ class TicketController extends BaseController
|
|||||||
'claim_type' => ['label' => 'Claim Type','rules' => 'required',
|
'claim_type' => ['label' => 'Claim Type','rules' => 'required',
|
||||||
'errors' => ['required' => 'Claim Type is required']
|
'errors' => ['required' => 'Claim Type is required']
|
||||||
],
|
],
|
||||||
'hospital_name' => ['label' => 'Hospital Name','rules' => 'required',
|
'hospital_name' => [
|
||||||
'errors' => ['required' => 'Hospital Name is required']
|
'label' => 'Hospital Name',
|
||||||
|
'rules' => 'required|regex_match[/^[a-zA-Z0-9\s\-_.\']+$/]',
|
||||||
|
'errors' => [
|
||||||
|
'required' => 'Hospital Name is required',
|
||||||
|
'regex_match' => 'The {field} can only contain letters, numbers, spaces, dashes, underscores, dots, and apostrophes.'
|
||||||
|
]
|
||||||
],
|
],
|
||||||
'hospital_address' => ['label' => 'Hospital Address','rules' => 'required',
|
'hospital_address' => [
|
||||||
'errors' => ['required' => 'Hospital Address is required']
|
'label' => 'Hospital Address',
|
||||||
|
'rules' => 'permit_empty|regex_match[/^[a-zA-Z0-9\s\-_.,#\/]+$/]',
|
||||||
|
'errors' => [
|
||||||
|
'regex_match' => 'The {field} contains invalid characters (Allowed: letters, numbers, spaces, dashes, commas, dots, # and /).'
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'hospital_city' => ['label' => 'Hospital City','rules' => 'required',
|
'hospital_state' => [
|
||||||
'errors' => ['required' => 'City is required']
|
'label' => 'Hospital State',
|
||||||
|
'rules' => 'permit_empty|regex_match[/^[a-zA-Z\s\-]+$/]',
|
||||||
|
'errors' => [
|
||||||
|
'regex_match' => 'Hospital State name can only contain letters, spaces, and hyphens.'
|
||||||
|
]
|
||||||
],
|
],
|
||||||
'hospital_state' => ['label' => 'Hospital State','rules' => 'required',
|
'hospital_city' => [
|
||||||
'errors' => ['required' => 'State is required']
|
'label' => 'Hospital City', // Added label for consistency
|
||||||
|
'rules' => 'permit_empty|regex_match[/^[a-zA-Z\s\-]+$/]',
|
||||||
|
'errors' => [
|
||||||
|
'regex_match' => 'Hospital City can only contain letters, spaces, and hyphens.'
|
||||||
|
]
|
||||||
],
|
],
|
||||||
'hospital_pin_code' => ['label' => 'Hospital Pincode','rules' => 'required|numeric|exact_length[6]',
|
'hospital_pin_code' => [
|
||||||
'errors' => ['exact_length' => 'Pincode must be 6 digits']
|
'label' => 'Hospital Pincode',
|
||||||
|
'rules' => 'permit_empty|numeric|exact_length[6]',
|
||||||
|
'errors' => [
|
||||||
|
'numeric' => 'Hospital Pincode must be digits only.',
|
||||||
|
'exact_length' => 'Hospital Pincode must be exactly 6 digits.'
|
||||||
|
]
|
||||||
],
|
],
|
||||||
'hospital_phone_no' => ['label' => 'Hospital Phone','rules' => 'required|numeric|min_length[10]',
|
'hospital_phone_no' => [
|
||||||
'errors' => ['min_length' => 'Phone number too short']
|
'label' => 'Hospital Phone',
|
||||||
|
'rules' => 'permit_empty|numeric|min_length[10]|max_length[15]',
|
||||||
|
'errors' => [
|
||||||
|
'numeric' => 'Phone number must contain only digits.',
|
||||||
|
'min_length' => 'Phone number is too short.',
|
||||||
|
'max_length' => 'Phone number is too long.'
|
||||||
|
]
|
||||||
],
|
],
|
||||||
'doa' => ['label' => 'DOA', 'rules' => 'required',
|
'doa' => ['label' => 'DOA', 'rules' => 'required',
|
||||||
'errors' => ['required' => 'Date of Admission is required']
|
'errors' => ['required' => 'Date of Admission is required']
|
||||||
@ -3138,11 +3180,12 @@ class TicketController extends BaseController
|
|||||||
],
|
],
|
||||||
'url.*' => [
|
'url.*' => [
|
||||||
'label' => 'URL',
|
'label' => 'URL',
|
||||||
'rules' => 'required',
|
'rules' => 'if_exist|required|regex_match[/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/]',
|
||||||
'errors' => [
|
'errors' => [
|
||||||
'required' => 'URL is required',
|
'required' => 'URL is required.',
|
||||||
|
'regex_match' => 'The URL format is invalid. Example: www.google.com or https://google.com'
|
||||||
]
|
]
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!$this->validate($rules)) {
|
if (!$this->validate($rules)) {
|
||||||
|
|||||||
@ -114,11 +114,13 @@ class UserController extends AdminController
|
|||||||
// Employee Code
|
// Employee Code
|
||||||
// ======================
|
// ======================
|
||||||
'emp_code' => [
|
'emp_code' => [
|
||||||
'rules' => 'required|min_length[3]|max_length[15]',
|
'label' => 'Employee Code',
|
||||||
|
'rules' => 'required|min_length[3]|max_length[15]|regex_match[/^[a-zA-Z0-9_\-\/]+$/]',
|
||||||
'errors' => [
|
'errors' => [
|
||||||
'required' => 'Employee Code is required',
|
'required' => 'Employee Code is required',
|
||||||
'min_length' => 'Employee Code must be at least 3 characters',
|
'min_length' => 'Employee Code must be at least 3 characters',
|
||||||
'max_length' => 'Employee Code cannot exceed 15 characters',
|
'max_length' => 'Employee Code cannot exceed 15 characters',
|
||||||
|
'regex_match' => 'Employee Code can only contain letters, numbers, underscores, hyphens, and forward slashes (/).'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
|
||||||
@ -178,13 +180,10 @@ class UserController extends AdminController
|
|||||||
]
|
]
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
if (!$this->validate($rules)) {
|
if (!$this->validate($rules)) {
|
||||||
return $this->response->setStatusCode(400)->setJSON([
|
return redirect()->to(base_url('/user/list'))
|
||||||
'status' => false,
|
->withInput()
|
||||||
'message' => 'Input validation failed',
|
->with('errors', $this->validator->getErrors());
|
||||||
'code' => 400,
|
|
||||||
'errors' => $this->validator->getErrors()
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$userData['created_by'] = get_session_userid();
|
$userData['created_by'] = get_session_userid();
|
||||||
@ -298,11 +297,13 @@ class UserController extends AdminController
|
|||||||
// Employee Code
|
// Employee Code
|
||||||
// ======================
|
// ======================
|
||||||
'emp_code' => [
|
'emp_code' => [
|
||||||
'rules' => 'required|min_length[3]|max_length[15]',
|
'label' => 'Employee Code',
|
||||||
|
'rules' => 'required|min_length[3]|max_length[15]|regex_match[/^[a-zA-Z0-9_\-\/]+$/]',
|
||||||
'errors' => [
|
'errors' => [
|
||||||
'required' => 'Employee Code is required',
|
'required' => 'Employee Code is required',
|
||||||
'min_length' => 'Employee Code must be at least 3 characters',
|
'min_length' => 'Employee Code must be at least 3 characters',
|
||||||
'max_length' => 'Employee Code cannot exceed 15 characters',
|
'max_length' => 'Employee Code cannot exceed 15 characters',
|
||||||
|
'regex_match' => 'Employee Code can only contain letters, numbers, underscores, hyphens, and forward slashes (/).'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
|
||||||
@ -363,12 +364,9 @@ class UserController extends AdminController
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
if (!$this->validate($rules)) {
|
if (!$this->validate($rules)) {
|
||||||
return $this->response->setStatusCode(400)->setJSON([
|
return redirect()->to(base_url('/user/list'))
|
||||||
'status' => false,
|
->withInput()
|
||||||
'message' => 'Input validation failed',
|
->with('errors', $this->validator->getErrors());
|
||||||
'code' => 400,
|
|
||||||
'errors' => $this->validator->getErrors()
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $this->request->getPost();
|
$data = $this->request->getPost();
|
||||||
@ -845,7 +843,7 @@ class UserController extends AdminController
|
|||||||
],
|
],
|
||||||
'errors' => [
|
'errors' => [
|
||||||
'required' => 'Retention Rate is required',
|
'required' => 'Retention Rate is required',
|
||||||
'regex_match' => 'Retention Rate must be between 0 and 100 with up to 2 decimal places'
|
'regex_match' => 'Retention Rate must be between 0 to 100 with up to 2 decimal places'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
// ======================
|
// ======================
|
||||||
|
|||||||
@ -884,12 +884,18 @@ table.dataTable tbody td {
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<?php if (session()->getFlashdata('errors')): ?>
|
||||||
|
<script>
|
||||||
|
$(document).ready(function() {
|
||||||
|
<?php foreach (session()->getFlashdata('errors') as $error): ?>
|
||||||
|
toastr.error("<?= addslashes($error) ?>", "Validation Error");
|
||||||
|
<?php endforeach; ?>
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php if (session()->getFlashdata('error')) : ?>
|
<?php if (session()->getFlashdata('error')) : ?>
|
||||||
<?php foreach (session()->getFlashdata('error') as $error) : ?>
|
|
||||||
<script>
|
|
||||||
toastr.error("<?= esc($error) ?>", "Validation Error");
|
|
||||||
</script>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var errorModal = new bootstrap.Modal(
|
var errorModal = new bootstrap.Modal(
|
||||||
|
|||||||
@ -415,44 +415,60 @@ input:checked + .slider:before {
|
|||||||
|
|
||||||
|
|
||||||
function validateFile(input) {
|
function validateFile(input) {
|
||||||
|
if (!input.files || !input.files[0]) return;
|
||||||
|
|
||||||
const file = input.files[0];
|
const file = input.files[0];
|
||||||
const allowedExtensions = ["jpg", "jpeg", "png"];
|
const allowedExtensions = ["jpg", "jpeg", "png"];
|
||||||
const fileExtension = file.name.split(".").pop().toLowerCase();
|
const fileExtension = file.name.split(".").pop().toLowerCase();
|
||||||
|
const fileSize = file.size / 1024; // KB
|
||||||
|
|
||||||
|
// Log Initial Info
|
||||||
|
console.log("File Selected:", file.name);
|
||||||
|
console.log("File Size:", fileSize.toFixed(2) + " KB");
|
||||||
|
|
||||||
// Check if the file extension is allowed
|
// Check if the file extension is allowed
|
||||||
if (!allowedExtensions.includes(fileExtension)) {
|
if (!allowedExtensions.includes(fileExtension)) {
|
||||||
toastr.warning('Only JPG, JPEG, PNG files are allowed.', 'Invalid file type.');
|
toastr.warning('Only JPG, JPEG, PNG files are allowed.', 'Invalid file type.');
|
||||||
$("#uploadPreview").attr("src", "<?= base_url()?>/public/assets/images/avatar_2x.png");
|
resetImageInput(input);
|
||||||
input.value = "";
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Check file size
|
// Check file size
|
||||||
const fileSize = file.size / 1024; // in KB
|
|
||||||
if (fileSize > 200) {
|
if (fileSize > 200) {
|
||||||
|
console.error("Validation Failed: File too large (" + fileSize.toFixed(2) + " KB)");
|
||||||
toastr.warning('Maximum file size allowed is 200KB.', 'File size exceeds limit.');
|
toastr.warning('Maximum file size allowed is 200KB.', 'File size exceeds limit.');
|
||||||
$("#uploadPreview").attr("src", "<?= base_url()?>/public/assets/images/avatar_2x.png");
|
resetImageInput(input);
|
||||||
input.value = "";
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check image dimensions
|
// Check image dimensions
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
|
img.src = URL.createObjectURL(file);
|
||||||
img.onload = function() {
|
img.onload = function() {
|
||||||
|
console.log("Dimensions Detected:", this.width + "x" + this.height);
|
||||||
if (this.width !== 100 || this.height !== 100) {
|
if (this.width !== 100 || this.height !== 100) {
|
||||||
|
console.error("Validation Failed: Wrong dimensions.");
|
||||||
toastr.warning('Image dimensions should be 100x100 pixels.', 'Invalid image dimensions.');
|
toastr.warning('Image dimensions should be 100x100 pixels.', 'Invalid image dimensions.');
|
||||||
$("#uploadPreview").attr("src", "<?= base_url()?>/public/assets/images/avatar_2x.png");
|
resetImageInput(input); // CRITICAL: This stops the file from being sent
|
||||||
}
|
}else {
|
||||||
|
console.log("Validation Passed: Image is 100x100 and under 200KB.");
|
||||||
// If both size and dimensions are valid, you can proceed with your logic here
|
// If both size and dimensions are valid, you can proceed with your logic here
|
||||||
// For example, you can display the image
|
// For example, you can display the image
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.onload = function(e) {
|
reader.onload = function(e) {
|
||||||
document.getElementById("uploadPreview").src = e.target.result;
|
$("#uploadPreview").attr("src", e.target.result);
|
||||||
};
|
};
|
||||||
reader.readAsDataURL(file);
|
reader.readAsDataURL(file);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
img.src = URL.createObjectURL(file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper function to clear the preview and the file input
|
||||||
|
function resetImageInput(input) {
|
||||||
|
input.value = ""; // This clears the file so it won't be submitted
|
||||||
|
$("#uploadPreview").attr("src", "<?= base_url()?>/public/assets/images/avatar_2x.png");
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
@ -108,11 +108,36 @@ $("#drive_file_upload_form").submit(function(event) {
|
|||||||
$('#drive_file_upload_form')[0].reset();
|
$('#drive_file_upload_form')[0].reset();
|
||||||
|
|
||||||
},
|
},
|
||||||
error: function (xhr, status, error) {
|
error:function (xhr) {
|
||||||
console.error(xhr.responseText);
|
|
||||||
console.error(status, error);
|
if (xhr.status === 400) {
|
||||||
|
let response = JSON.parse(xhr.responseText);
|
||||||
|
let errorMessages = "";
|
||||||
|
let seenMessages = []; // Array to store unique messages
|
||||||
|
if (response.errors) {
|
||||||
|
$.each(response.errors, function (field, message) {
|
||||||
|
if (!seenMessages.includes(message)) {
|
||||||
|
errorMessages += `• ${message}<br>`;
|
||||||
|
seenMessages.push(message); // Mark this message as "seen"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
toastr.error(errorMessages, 'Validation Error', { "allowHtml": true });
|
||||||
|
} else {
|
||||||
|
toastr.warning(response.message || 'Validation failed', 'Warning');
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (xhr.status === 403) {
|
||||||
|
let response = JSON.parse(xhr.responseText);
|
||||||
|
toastr.error(response.message, 'Security Policy');
|
||||||
|
} else if (xhr.status === 500) {
|
||||||
|
toastr.error('Something went wrong . Please try again later.', 'Server Error');
|
||||||
|
} else {
|
||||||
|
toastr.error('An unexpected error occurred. Please try again later.', 'Error');
|
||||||
|
}
|
||||||
|
|
||||||
$('.loader').fadeOut();
|
$('.loader').fadeOut();
|
||||||
$('.loader-mask').delay(350).fadeOut('slow');
|
$('.loader-mask').delay(350).fadeOut('slow');
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -573,7 +573,8 @@ if (isset($selected_lead_type)) {
|
|||||||
<input type="text" class="form-control" name="docs_name_${increment}[]" placeholder="${placeholder}">
|
<input type="text" class="form-control" name="docs_name_${increment}[]" placeholder="${placeholder}">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group col-md-5">
|
<div class="form-group col-md-5">
|
||||||
<label>File Upload<span class="text-danger"></span></label>
|
<label>File Upload<span class="text-danger"></span></label><br>
|
||||||
|
<span class="text-danger">PDF | Excel (XLSX, XLS) | Images (PNG, JPG)</span>
|
||||||
<input type="file" class="form-control" id="file_name_${fileIndex}" name="file_name_${increment}[]" accept="${accept}">
|
<input type="file" class="form-control" id="file_name_${fileIndex}" name="file_name_${increment}[]" accept="${accept}">
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-2" style="position: relative; bottom: 16px;">
|
<div class="col-md-2" style="position: relative; bottom: 16px;">
|
||||||
@ -638,7 +639,8 @@ if (isset($selected_lead_type)) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-auto" style="align-content: center;">
|
<div class="col-auto" style="align-content: center;">
|
||||||
<label>File Upload </label>
|
<label>File Upload </label> <br>
|
||||||
|
<span class="text-danger">PDF | Excel (XLSX, XLS) | Images (PNG, JPG)</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<div class="input-icon">
|
<div class="input-icon">
|
||||||
|
|||||||
@ -741,12 +741,12 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group col-md-3">
|
<div class="form-group col-md-3">
|
||||||
<label for="bp_cgst">D.O.C</label>
|
<label for="bp_cgst">D.O.C <span class="text-danger">*</span></label>
|
||||||
<input id="policy_start_date" type="text" class="form-control" name="policy_start_date" placeholder="DD/MM/YYYY" >
|
<input id="policy_start_date" type="text" class="form-control" name="policy_start_date" placeholder="DD/MM/YYYY" >
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group col-md-3">
|
<div class="form-group col-md-3">
|
||||||
<label for="bp_igst">D.O.E</label>
|
<label for="bp_igst">D.O.E <span class="text-danger">*</span></label>
|
||||||
<input id="policy_end_date" type="text" class="form-control" name="policy_end_date" placeholder="DD/MM/YYYY" >
|
<input id="policy_end_date" type="text" class="form-control" name="policy_end_date" placeholder="DD/MM/YYYY" >
|
||||||
</div>
|
</div>
|
||||||
<!--
|
<!--
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user