MERGE_TEST_FORM_VALIDATIONS_DONE

This commit is contained in:
Ubuntu 2026-02-13 17:58:05 +05:30
commit bc8a11aae5
10 changed files with 6078 additions and 5922 deletions

View File

@ -2689,7 +2689,7 @@ class ClientController extends AdminController
'errors' => ['required' => 'Please select a Client Branch.']
],
'policy_type_id' => [
'rules' => 'required|is_natural_no_zero',
'rules' => ['required', 'is_natural_no_zero'],
'errors' => [
'required' => 'Policy Type is required.',
'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_\-\/\\\]+$/]'],
'errors' => [
'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' => [
'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' => [
'required' => 'GST percentage is required.',
'numeric' => 'GST must be a valid number.',
@ -2735,16 +2740,31 @@ class ClientController extends AdminController
'rules' => 'permit_empty'
],
'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.']
],
// --- CHECKBOXES (Permit Empty) ---
'enrolment_visibility' => ['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([
'status' => false,
'message' => 'Input validation failed',
@ -2851,13 +2871,12 @@ class ClientController extends AdminController
public function editClientPolicy()
{
$rules = [
// --- BASIC SELECTS (Required) ---
'client_branch_id' => [
'rules' => 'required',
'errors' => ['required' => 'Please select a Client Branch.']
],
'policy_type_id' => [
'rules' => 'required|is_natural_no_zero',
'rules' => ['required', 'is_natural_no_zero'],
'errors' => [
'required' => 'Policy Type is required.',
'is_natural_no_zero' => 'Please select a valid Policy Type.'
@ -2871,17 +2890,20 @@ class ClientController extends AdminController
'rules' => 'required',
'errors' => ['required' => 'Please select a TPA.']
],
// --- TEXT FIELDS (Required & Specific Format) ---
'policy_no' => [
'rules' => 'required|regex_match[/^[a-zA-Z0-9\s_\-\/\\\]+$/]',
'rules' => ['required', 'regex_match[/^[a-zA-Z0-9\s_\-\/\\\]+$/]'],
'errors' => [
'required' => 'This field is required.',
'regex_match' => 'Only letters, numbers, spaces, _, -, /, and \ are allowed.'
'required' => 'Policy No is required.',
'regex_match' => 'Invalid characters in Policy No.'
]
],
'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' => [
'required' => 'GST percentage is required.',
'numeric' => 'GST must be a valid number.',
@ -2889,47 +2911,47 @@ class ClientController extends AdminController
'less_than_equal_to' => 'GST percentage cannot exceed 100%.'
]
],
// --- DATE FIELDS (Required) ---
'policy_start_date' => [
'rules' => 'required|valid_date',
'errors' => [
'required' => 'Start date is required.',
'valid_date' => 'Enter a valid date format (YYYY-MM-DD).'
]
'rules' => 'required',
'errors' => ['required' => 'Start date is required.']
],
'policy_end_date' => [
'rules' => 'required|valid_date',
'errors' => [
'required' => 'End date is required.',
'valid_date' => 'Enter a valid date format (YYYY-MM-DD).'
]
],
// --- PERMIT EMPTY FIELDS (Optional) ---
'base_policy' => [
'rules' => 'permit_empty'
'rules' => 'required',
'errors' => ['required' => 'End date is required.']
],
'wellness_plan_id' => [
'rules' => 'permit_empty|alpha_numeric',
'errors' => [
'alpha_numeric' => 'Wellness Plan ID can only contain letters and numbers (no spaces or special characters).'
]
'errors' => ['alpha_numeric' => 'Wellness Plan ID can only contain letters and numbers.']
],
'wellness_vendor_id' => [
'rules' => 'permit_empty'
],
'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.']
],
// --- CHECKBOXES (Permit Empty) ---
'enrolment_visibility' => ['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([
'status' => false,
'message' => 'Input validation failed',

View File

@ -365,6 +365,7 @@ class LeadsController extends BaseController
{
// print_r($this->request->getPost()); die;
$id = $this->request->getPost('id');
$postData = $this->request->getPost();
$data = $this->prepareLeadData();
$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) {
$rules['client_type'] = [
'rules' => 'required',
@ -793,7 +809,7 @@ class LeadsController extends BaseController
'source_policy_end_date' => $data['source_policy_end_date'] ?? null,
'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
];
}

File diff suppressed because it is too large Load Diff

View File

@ -1216,37 +1216,51 @@ class TicketController extends BaseController
'claim_type' => ['label' => 'Claim Type','rules' => 'required',
'errors' => ['required' => 'Claim Type is required']
],
'hospital_name' => ['label' => 'Hospital Name','rules' => 'required',
'errors' => ['required' => 'Hospital Name is required']
'hospital_name' => [
'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',
'errors' => ['required' => 'Hospital Address is required']
'hospital_address' => [
'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' => [
'label' => 'hospital_State',
'rules' => 'required|regex_match[/^[a-zA-Z\s\-]+$/]',
'errors' => [
'required' => 'Hospital State is required.',
'regex_match' => 'Hospital State name can only contain letters, spaces, and hyphens.'
]
],
'hospital_city' => [
'rules' => 'required|regex_match[/^[a-zA-Z0-9\s\-]+$/]',
'errors' => [
'required' => 'Hospital City is required',
'regex_match' => 'Hospital City can contain letters, numbers, spaces, and hyphens.'
]
],
'hospital_pin_code' => [
'rules' => 'required|numeric|exact_length[6]',
'errors' => [
'required' => 'Hospital Pincode is required.',
'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]',
'errors' => ['min_length' => 'Phone number too short']
'hospital_state' => [
'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_city' => [
'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' => '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' => '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',
'errors' => ['required' => 'Date of Admission is required']
@ -1551,23 +1565,51 @@ class TicketController extends BaseController
'claim_type' => ['label' => 'Claim Type','rules' => 'required',
'errors' => ['required' => 'Claim Type is required']
],
'hospital_name' => ['label' => 'Hospital Name','rules' => 'required',
'errors' => ['required' => 'Hospital Name is required']
'hospital_name' => [
'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',
'errors' => ['required' => 'Hospital Address is required']
'hospital_address' => [
'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',
'errors' => ['required' => 'City is required']
'hospital_state' => [
'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',
'errors' => ['required' => 'State is required']
'hospital_city' => [
'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]',
'errors' => ['exact_length' => 'Pincode must be 6 digits']
'hospital_pin_code' => [
'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]',
'errors' => ['min_length' => 'Phone number too short']
'hospital_phone_no' => [
'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',
'errors' => ['required' => 'Date of Admission is required']
@ -3138,11 +3180,12 @@ class TicketController extends BaseController
],
'url.*' => [
'label' => 'URL',
'rules' => 'required',
'rules' => 'if_exist|required|regex_match[/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/]',
'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)) {

View File

@ -114,11 +114,13 @@ class UserController extends AdminController
// Employee 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' => [
'required' => 'Employee Code is required',
'min_length' => 'Employee Code must be at least 3 characters',
'max_length' => 'Employee Code cannot exceed 15 characters',
'required' => 'Employee Code is required',
'min_length' => 'Employee Code must be at least 3 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)) {
return $this->response->setStatusCode(400)->setJSON([
'status' => false,
'message' => 'Input validation failed',
'code' => 400,
'errors' => $this->validator->getErrors()
]);
if (!$this->validate($rules)) {
return redirect()->to(base_url('/user/list'))
->withInput()
->with('errors', $this->validator->getErrors());
}
$userData['created_by'] = get_session_userid();
@ -298,11 +297,13 @@ class UserController extends AdminController
// Employee 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' => [
'required' => 'Employee Code is required',
'min_length' => 'Employee Code must be at least 3 characters',
'max_length' => 'Employee Code cannot exceed 15 characters',
'required' => 'Employee Code is required',
'min_length' => 'Employee Code must be at least 3 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)) {
return $this->response->setStatusCode(400)->setJSON([
'status' => false,
'message' => 'Input validation failed',
'code' => 400,
'errors' => $this->validator->getErrors()
]);
return redirect()->to(base_url('/user/list'))
->withInput()
->with('errors', $this->validator->getErrors());
}
$data = $this->request->getPost();
@ -845,7 +843,7 @@ class UserController extends AdminController
],
'errors' => [
'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'
]
],
// ======================

View File

@ -884,12 +884,18 @@ table.dataTable tbody td {
</table>
</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 foreach (session()->getFlashdata('error') as $error) : ?>
<script>
toastr.error("<?= esc($error) ?>", "Validation Error");
</script>
<?php endforeach; ?>
<script>
var errorModal = new bootstrap.Modal(

View File

@ -415,44 +415,60 @@ input:checked + .slider:before {
function validateFile(input) {
if (!input.files || !input.files[0]) return;
const file = input.files[0];
const allowedExtensions = ["jpg", "jpeg", "png"];
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
if (!allowedExtensions.includes(fileExtension)) {
toastr.warning('Only JPG, JPEG, PNG files are allowed.', 'Invalid file type.');
$("#uploadPreview").attr("src", "<?= base_url()?>/public/assets/images/avatar_2x.png");
input.value = "";
resetImageInput(input);
return;
}
// Check file size
const fileSize = file.size / 1024; // in KB
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.');
$("#uploadPreview").attr("src", "<?= base_url()?>/public/assets/images/avatar_2x.png");
input.value = "";
resetImageInput(input);
return;
}
// Check image dimensions
const img = new Image();
img.src = URL.createObjectURL(file);
img.onload = function() {
console.log("Dimensions Detected:", this.width + "x" + this.height);
if (this.width !== 100 || this.height !== 100) {
console.error("Validation Failed: Wrong 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
// For example, you can display the image
const reader = new FileReader();
reader.onload = function(e) {
document.getElementById("uploadPreview").src = e.target.result;
$("#uploadPreview").attr("src", e.target.result);
};
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>

View File

@ -108,11 +108,36 @@ $("#drive_file_upload_form").submit(function(event) {
$('#drive_file_upload_form')[0].reset();
},
error: function (xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
error:function (xhr) {
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-mask').delay(350).fadeOut('slow');
}
});
});

View File

@ -573,7 +573,8 @@ if (isset($selected_lead_type)) {
<input type="text" class="form-control" name="docs_name_${increment}[]" placeholder="${placeholder}">
</div>
<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}">
</div>
<div class="col-md-2" style="position: relative; bottom: 16px;">
@ -638,7 +639,8 @@ if (isset($selected_lead_type)) {
</div>
<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 class="col-md-3">
<div class="input-icon">

View File

@ -741,12 +741,12 @@
</div>
<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" >
</div>
<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" >
</div>
<!--