vb_book/app/Views/customer_form.php
2024-12-21 16:45:16 +05:30

681 lines
42 KiB
PHP
Executable File

<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<?php $fullName = trim( (isset($customer['first_name']) ? $customer['first_name'] : '' ). ' ' .
(isset($customer['last_name']) ? $customer['last_name'] : '')
);
?>
<h4 class="header-title"><?= $page_name === 'Edit Customer Details' ? htmlspecialchars($fullName)." - Customer Details" : $page_name; ?></h4>
<?php if (session()->getFlashdata('success') || session()->getFlashdata('error')) : ?>
<?php if (session()->getFlashdata('success')) : ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<?= session('success') ?>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<?php endif; ?>
<?php if (session()->getFlashdata('error')) : ?>
<div id = 'errorAlert' class="alert alert-danger alert-dismissible fade show" role="alert">
<?= session('error') ?>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<?php endif; ?>
<?php endif; ?>
<?php if ($page_name === 'Edit Customer Details') : ?>
<ul class="nav nav-tabs" id="customerTabs" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="customerDetails-tab" data-toggle="tab" href="#customerDetails" role="tab" aria-controls="customerDetails" aria-selected="true">Customer Details</a>
</li>
<li class="nav-item">
<a class="nav-link" id="subscriptionDetails-tab" data-toggle="tab" href="#subscriptionDetails" role="tab" aria-controls="subscriptionDetails" aria-selected="false">Subscription Details</a>
</li>
<li class="nav-item">
<a class="nav-link" id="invoiceDetails-tab" data-toggle="tab" href="#invoiceDetails" role="tab" aria-controls="invoiceDetails" aria-selected="false">Invoice Details</a>
</li>
</ul>
<?php endif; ?>
<div class="tab-content">
<!-- Customer Details Tab -->
<div class="tab-pane fade show active" id="customerDetails" role="tabpanel" aria-labelledby="customerDetails-tab">
<!-- Customer details form fields -->
<form class="needs-validation parsley-examples" novalidate method="POST" enctype="multipart/form-data" action="<?= base_url() . "insert_customer"; ?>" id="myForm" name="myForm" onsubmit="myFunction(event)">
<!-- <img src="<?= base_url() . "public/assets/images/plugins/loading.gif" ?>" alt="loader1" style="display:none; height:30px; width:auto;" id="loaderImg"> -->
<div class="form-row">
<div class="form-group col-md-4">
<label for="cfname" class="col-form-label">First Name<span class="text-danger"> *</span></label>
<input type="text" class="form-control" id="cfname" name="cfname" value="<?= isset($customer['first_name']) ? $customer['first_name'] : '' ?>" placeholder="First Name" required />
</div>
<div class="form-group col-md-4">
<label for="csname" class="col-form-label">Last Name<span class="text-danger"> </span></label>
<input type="text" class="form-control" name="csname" value="<?= isset($customer['last_name']) ? $customer['last_name'] : '' ?>" placeholder="Last Name" />
</div>
<div class="form-group col-md-4">
<label for="cmail" class="col-form-label">Email<span class="text-danger"> </span></label>
<input type="text" class="form-control" id="cmail" name="cmail" value="<?= isset($customer['email']) ? $customer['email'] : '' ?>" placeholder="Email" onkeyup="validateEmail(this.value)" onchange="checkExisting(this.value,'email','cmail')" />
<span id="emailValidationMessage"></span>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-4">
<label for="cmobile" class="col-form-label">Mobile/Landline<span class="text-danger"> *</span></label>
<input type="text" class="form-control" id="cmobile" name="cmobile" value="<?= isset($customer['mobile_no']) ? $customer['mobile_no'] : '' ?>" placeholder="Mobile Number (Enter only numbers)" required minlength="10" onkeypress="return restriction(event)" onchange="checkExisting(this.value,'mobile_no','cmobile')" />
<span id="mobileValidationMessage"></span>
</div>
<div class="form-group col-md-4">
<label for="dob" class="col-form-label">Date Of Birth</label>
<input type="date" class="form-control" name="dob" value="<?= isset($customer['date_of_birth']) ? $customer['date_of_birth'] : '' ?>" max="<?= date('Y-m-d', strtotime('-18 years')); ?>" placeholder="Date Of Birth" />
</div>
</div>
<input type="hidden" id="customer_id" name="customer_id" placeholder="hidden for customer id" value="<?= isset($customer['customer_id']) ? $customer['customer_id'] : '' ?>" />
<input type="hidden" id="business_id" name="business_id" placeholder="hidden for business id" value="<?= $session_bid ?>" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<br />
<div class="form-row">
<div class="col-md-6 text-left">
<h5> Billing Address </h5>
</div>
</div>
<div class="after-add-more">
<hr />
<div class="form-group">
<!-- <div class="form-row">
<div class="form-group col-md-6">
<label for="bfname" class="col-form-label">First Name<span class="text-danger"> *</span></label>
<input type="text" class="form-control" id="bfname" name="bfname[]" value="<?= isset($customer['first_name']) ? $customer['first_name'] : '' ?>" placeholder="First Name" required />
<div class="invalid-feedback"> Please provide. </div>
</div>
<div class="form-group col-md-6">
<label for="blname" class="col-form-label">Last Name<span class="text-danger"> *</span></label>
<input type="text" class="form-control" id="blname" name="blname[]" value="<?= isset($customer['last_name']) ? $customer['last_name'] : '' ?>" placeholder="Last Name" required />
<div class="invalid-feedback"> Please provide. </div>
</div>
</div> -->
<!-- <div class="form-row">
<div class="form-group col-md-4">
<label for="bcname" class="col-form-label">Company<span class="text-danger"> *</span></label>
<input type="text" class="form-control" id="bcname" name="bcname[]" value="<?= isset($customer['Company']) ? $customer['Company'] : '' ?>" placeholder="Company" required />
<div class="invalid-feedback"> Please provide. </div>
</div>
<div class="form-group col-md-4">
<label for="bemail" class="col-form-label">Email<span class="text-danger"> *</span></label>
<input type="text" class="form-control" id="bemail" name="bemail[]" value="<?= isset($customer['email']) ? $customer['email'] : '' ?>" placeholder="Email" required />
<div class="invalid-feedback"> Please provide. </div>
</div>
<div class="form-group col-md-4">
<label for="bmobile" class="col-form-label">Mobile<span class="text-danger"> *</span></label>
<input type="number" class="form-control" id="bmobile" name="bmobile[]" value="<?= isset($customer['mobile_no']) ? $customer['mobile_no'] : '' ?>" placeholder="Mobile Number (Enter only numbers)" required />
<div class="invalid-feedback"> Please provide. </div>
</div>
</div> -->
<div class="form-row">
<div class="form-group col-md-6">
<label for="baddress1" class="col-form-label">Address 1<span class="text-danger"> *</span></label>
<input type="text" class="form-control" id="baddress1" name="baddress1[]" placeholder="Address (eg : 1234 Main St)" required />
</div>
<div class="form-group col-md-6">
<label for="baddress2" class="col-form-label">Address 2<span class="text-danger"> </span></label>
<input type="text" class="form-control" id="baddress2" name="baddress2[]" placeholder="Address (eg : 1234 Main St)" />
</div>
</div>
<div class="form-row">
<div class="form-group col-md-3">
<label for="bcountry" class="col-form-label">Country<span class="text-danger"> *</span></label>
<select class="form-control" id="bcountry" name="bcountry[]" required>
<option selected value="India">India</option>
<?php foreach ($country_details as $value) { ?>
<option value="<?php echo $value['country_short_name']; ?>">
<?php echo $value['country_name']; ?>
</option>
<?php } ?>
</select>
</div>
<div class="form-group col-md-3">
<div id="billinput" style="display: block">
<label for="bistate" class="col-form-label">State</label>
<input type="text" class="form-control" id="bistate" name="bistate[]" value="Tamil Nadu" />
</div>
<div id="billdropdown" style="display: none">
<label for="bdstate" class="col-form-label">State</label>
<select class="form-control" id="bdstate" name="bdstate[]">
<option selected value="Tamil Nadu">Tamil Nadu</option>
<?php foreach ($state_details as $value) { ?>
<option value="<?php echo $value['state_short_name']; ?>">
<?php echo $value['state_name']; ?>
</option>
<?php } ?>
</select>
<!-- <div class="invalid-feedback"> Please provide. </div> -->
</div>
</div>
<div class="form-group col-md-3">
<label for="bcity" class="col-form-label">City<span class="text-danger"> *</span></label>
<input type="text" class="form-control" id="bcity" name="bcity[]" placeholder="City" required />
</div>
<div class="form-group col-md-3">
<label for="bzip" class="col-form-label">Postal Code<span class="text-danger"> *</span></label>
<input type="number" class="form-control" id="bzip" name="bzip[]" placeholder="Postal Code" required pattern="\d*" maxlength="6" oninput="this.value=this.value.slice(0, this.maxLength)" pattern="\d{6}" title="Please enter a 6-digit postal code." />
</div>
</div>
<input type="hidden" id="bcustomer_address_id" name="bcustomer_address_id[]" placeholder="hidden for billing customer address id" />
</div>
</div>
<br />
<div class="form-row">
<div class="col-md-6 text-left">
<h5> Shipping Address </h5>
</div>
<div class="col-md-6 text-right checkbox checkbox-purple">
<input type="checkbox" id="addressCopiedAsShipping" />
<label for="addressCopiedAsShipping"> Is the above address same as the shipping address?</label>
</div>
</div>
<div class="after-shipping-addr-add-more">
<hr />
<div class="form-group">
<div class="form-row">
<div class="form-group col-md-4">
<label for="saddress1_name" class="col-form-label">Name of Shipping address Customer<span class="text-danger"> *</span></label>
<input type="text" class="form-control" id="saddress1_name" name="saddress1_name[]" value="<?= isset($customer['first_name']) ? $customer['first_name'] : '' ?>" required />
</div>
<div class="form-group col-md-4">
<label for="saddress1" class="col-form-label">Address 1<span class="text-danger"> *</span></label>
<input type="text" class="form-control" id="saddress1" name="saddress1[]" placeholder="Address (eg : 1234 Main St)" required />
</div>
<div class="form-group col-md-4">
<label for="saddress2" class="col-form-label">Address 2<span class="text-danger"> </span></label>
<input type="text" class="form-control" id="saddress2" name="saddress2[]" placeholder="Address (eg : 1234 Main St)" />
</div>
</div>
<div class="form-row">
<div class="form-group col-md-3">
<label for="scountry" class="col-form-label">Country<span class="text-danger"> *</span></label>
<input type="hidden" id="counter" value=<?= 0; ?> readonly />
<select class="form-control" id="scountry0" name="scountry[]" onchange="changeFields(this)" required>
<option selected value="India">India</option>
<?php foreach ($country_details as $value) { ?>
<option value="<?php echo $value['country_short_name']; ?>">
<?php echo $value['country_name']; ?>
</option>
<?php } ?>
</select>
</div>
<div class="form-group col-md-3">
<label for="" class="col-form-label">State</label>
<input type="text" class="form-control" id="sistate0" name="sistate[]" value="Tamil Nadu" style="display: block" />
<select class="form-control" id="sdstate0" name="sdstate[]" style="display: none">
<option selected value="Tamil Nadu">Tamil Nadu</option>
<?php foreach ($state_details as $value) { ?>
<option value="<?php echo $value['state_short_name']; ?>">
<?php echo $value['state_name']; ?>
</option>
<?php } ?>
</select>
<!-- <div class="invalid-feedback"> Please provide. </div> -->
</div>
<div class="form-group col-md-3">
<label for="scity" class="col-form-label">City<span class="text-danger"> *</span></label>
<input type="text" class="form-control" id="scity" name="scity[]" placeholder="City" required />
</div>
<div class="form-group col-md-3">
<label for="szip" class="col-form-label">Postal Code<span class="text-danger"> *</span></label>
<input type="number" class="form-control" id="szip" name="szip[]" placeholder="Postal Code" required pattern="\d*" maxlength="6" oninput="this.value=this.value.slice(0, this.maxLength)" pattern="\d{6}" title="Please enter a 6-digit postal code." />
</div>
</div>
<div class="form-row">
<div class="form-group col-md-3">
<input type="hidden" id="scustomer_address_id" name="scustomer_address_id[]" placeholder="hidden for shipping customer address id" />
</div>
<div class="form-group col-md-9 shipping-addr-div-change text-right m-b-0">
<a class="btn btn-success waves-effect waves-light mr-1 shipping-addr-add-more">+ Add More Shipping Address </a>
<a class="btn btn-danger waves-effect waves-light mr-1 shipping-addr-remove">- Remove </a>
</div>
</div>
</div>
</div>
<?php if (!empty($customer)) { ?>
<div class="form-group text-right m-b-0 checkbox checkbox-purple">
<input type="checkbox" id="isactive" name="isactive" class="form-control" <?= isset($customer) && $customer['isactive'] == 1 ? 'checked' : '' ?>>
<label for="isactive"> Is Active</label>
</div>
<br>
<?php } ?>
<div class="form-group text-right m-b-0">
<button class="btn btn-success waves-effect waves-light mr-1" id="submitBtn" type="submit">Submit</button>
<!-- <button type="reset" class="btn btn-primary waves-effect mr-1">Reset</button> -->
<button type="button" class="btn btn-primary waves-effect mr-1" onclick="refreshPage()">Reset</button>
<a href="<?= base_url() . "customer_list"; ?>" class="btn btn-secondary waves-effect">Cancel</a>
</div>
</form>
</div><!-- end customer Details Tab -->
<!-- Subscription Details Tab -->
<div class="tab-pane fade show " id="subscriptionDetails" role="tabpanel" aria-labelledby="subscriptionDetails-tab">
<?php if (!empty($subscriptions)) : ?>
<table class="table table-bordered">
<thead>
<tr>
<th>Subscription Name</th>
<th>From Subscription</th>
<th>To Subscription</th>
<th>Invoice Number</th>
<th>Invoice Status</th>
<th>Expiring Status</th>
</tr>
</thead>
<tbody>
<?php foreach ($subscriptions as $row) : ?>
<?php
$from_date = date('d/m/Y', strtotime($row->from_subscription));
$to_date = date('d/m/Y', strtotime($row->to_subscription));
$daysRemaining = (int)$row->subscription_in_days;
$fromDateTime = new DateTime($row->from_subscription);
$toDateTime = new DateTime($row->to_subscription);
$currentDate = new DateTime();
$currentDate->setTime(0, 0, 0);
$toDateTime->setTime(0, 0, 0);
$interval = $currentDate->diff($toDateTime);
$daysRemaining = $interval->days;
if ($currentDate > $toDateTime) {
$daysRemaining = -$daysRemaining;
}
if ($daysRemaining < 0) {
$class = 'text-danger';
$message = "Expired";
} elseif ($daysRemaining == 0) {
$class = 'text-danger';
$message = "Expires Today";
} elseif ($daysRemaining == 1) {
$class = 'text-warning';
$message = "Expires Tomorrow";
} elseif ($daysRemaining <= 7) {
$class = 'text-warning';
$message = "Expires in $daysRemaining days";
} else {
$class = 'text-success';
$message = "$daysRemaining days until expiration";
}
?>
<tr>
<td><?= $row->title ?></td>
<td><?= $row->formatted_from_subscription ?></td>
<td><?= $row->formatted_to_subscription ?></td>
<td><?= $row->invoice_number ?></td>
<td><?= $row->status ?></td>
<td><span class="<?php echo $class; ?>"><?php echo $message; ?></span></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else : ?>
<p>No subscriptions found for this customer.</p>
<?php endif; ?>
</div><!-- end subscription Details Tab -->
<!-- Invoice Details Tab -->
<div class="tab-pane fade" id="invoiceDetails" role="tabpanel" aria-labelledby="invoiceDetails-tab">
<?php if (!empty($invoices)) : ?>
<table class="table table-bordered">
<thead>
<tr>
<th>Invoice Number</th>
<th>Invoice Date</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<?php foreach ($invoices as $value) : ?>
<tr>
<td><?= $value->invoice_number ?></td>
<td><?= $value->formatted_invoice_date ?></td>
<td><?= '&#x20B9; '.$value->total_amount ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else : ?>
<p>No invoice found for this customer.</p>
<?php endif; ?>
</div><!-- end invoice Details Tab -->
</div><!-- end tab-content-->
</div><!-- end card-body-->
</div>
</div>
</div>
<script>
$("#addressCopiedAsShipping").on("change", function() {
var count = $(".after-shipping-addr-add-more").length;
var counter = $("#counter").val() === "" ? count : parseInt($("#counter").val(), 10);
if ($(this).is(":checked")) {
var customerAddress1 = $("#baddress1").val();
var customerAddress2 = $("#baddress2").val();
var customerCountry = $("#bcountry").val();
var customerDropdownState = $("#bdstate").val();
var customerInputState = $("#bistate").val();
var customerCity = $("#bcity").val();
var customerPostalCode = $("#bzip").val();
$("#saddress1").val(customerAddress1).prop("readonly", false);
$("#saddress2").val(customerAddress2).prop("readonly", false);
$("#scountry"+counter).val(customerCountry).prop("readonly", false);
if (customerCountry == 'IN') {
$("#sistate"+counter).val(customerInputState).css("display", "none").prop("readonly", false);
$("#sdstate"+counter).val(customerDropdownState).css("display", "block").prop("readonly", false);
} else {
$("#sistate"+counter).val(customerInputState).css("display", "block").prop("readonly", false);
$("#sdstate"+counter).val(customerDropdownState).css("display", "none").prop("readonly", false);
}
$("#scity").val(customerCity).prop("readonly", false);
$("#szip").val(customerPostalCode).prop("readonly", false);
$("#counter").val(counter++).prop("readonly", true);
} else {
// Clear the billing address fields when the checkbox is unchecked
$("#saddress1").val("").prop("readonly", false);
$("#saddress2").val("").prop("readonly", false);
$("#scity").val("").prop("readonly", false);
$("#scountry"+counter).val("").prop("readonly", false);
$("#sistate"+counter).val("").css("display", "block").prop("readonly", false);
$("#sdstate"+counter).val("").css("display", "none").prop("readonly", false);
$("#szip").val("").prop("readonly", false);
$("#scustomer_address_id").val("") // Hidden Field ressetted bcoz Adress history
}
var alert = $('#errorAlert').val();
console.log("The alert message is "+alert);
$('#myForm').parsley().validate();
});
$("#bcountry").on("change", function() {
var country = $("#bcountry").val();
var dropdownField = $("#billdropdown");
var textField = $("#billinput");
if (country === 'IN') {
dropdownField.show();
textField.hide();
} else {
dropdownField.hide();
textField.show();
}
});
$(document).ready(function() {
$('#cfname').on('change',function(){
var name = $('#cfname').val();
console.log(name);
$('#saddress1_name').val(name);
})
var barray = <?php echo json_encode($customer_billing); ?>;
if (barray.length > 0) {
for (var i = 0; i < barray.length; i++) {
$("#baddress1").val(barray[i]['address_1']);
$("#baddress2").val(barray[i]['address_2']);
$("#bcountry").val(barray[i]['country']);
$("#bcity").val(barray[i]['city']);
if (barray[i]['country'] == 'IN') {
$("#bdstate").val(barray[i]['state']);
$("#billdropdown").show();
$("#billinput").hide();
} else {
$("#bistate").val(barray[i]['state']);
$("#billdropdown").hide();
$("#billinput").show();
}
$("#bzip").val(barray[i]['postal_code']);
$('#bcustomer_address_id').val(barray[i]['customer_address_id']);
}
}
/*****************************************************************************************/
var sarray = <?php echo json_encode($customer_shipping); ?>;
if (sarray.length > 0) {
j = 0;
for (var i = 0; i < sarray.length; i++) {
if (i == 0) {
var html = $(".after-shipping-addr-add-more").first();
} else {
var html = $(".after-shipping-addr-add-more").first().clone();
}
if ((barray[0]['address_1'] == sarray[i]['address_1']) &&
(barray[0]['city'] == sarray[i]['city']) &&
(barray[0]['state'] == sarray[i]['state']) &&
(barray[0]['country'] == sarray[i]['country']) &&
(barray[0]['postal_code'] == sarray[i]['postal_code'])) {
$("#addressCopiedAsShipping").prop("checked", true);
}
html.find('input#scustomer_address_id').val(sarray[i]['customer_address_id']);
html.find('input#saddress1').val(sarray[i]['address_1']);
html.find('input#saddress2').val(sarray[i]['address_2']);
html.find('input#scity').val(sarray[i]['city']);
html.find('select#scountry0').val(sarray[i]['country']);
html.find('select#scountry0').attr('id', 'scountry' + j);
html.find('input#counter').val(j).prop("readonly", true);
if (sarray[i]['country'] === 'IN') {
// html.find('select#sdstate0').attr('id','sdstate'+$j).val(sarray[i]['state']);
html.find('select#sdstate0').attr('id', 'sdstate' + j).css("display", "block").val(sarray[i]['state']);
html.find('input#sistate0').attr('id', 'sistate' + j).css("display", "none").val('');
} else {
html.find('input#sistate0').attr('id', 'sistate' + j).css("display", "block").val(sarray[i]['state']);
html.find('select#sdstate0').attr('id', 'sdstate' + j).css("display", "none").val('');
}
html.find('input#szip').val(sarray[i]['postal_code']);
if (i !== 0) {
html.find(".shipping-addr-div-change").html("<a class='btn btn-success waves-effect waves-light mr-1 shipping-addr-add-more'>+ Add More Shipping Address </a><a class='btn btn-danger waves-effect waves-light mr-1 shipping-addr-remove'>- Remove </a>");
html.insertAfter(".after-shipping-addr-add-more:last");
}
j++;
toggleButtons();
}
} else {
toggleButtons();
}
$("body").on("click", ".shipping-addr-add-more", function() {
var html = $(".after-shipping-addr-add-more").first().clone();
var count = $(".after-shipping-addr-add-more").length;
html.find('select#scountry0').attr('id', 'scountry' + count).val('')
html.find('select#sdstate0').attr('id', 'sdstate' + count).css("display", "none").val('');
html.find('input#sistate0').attr('id', 'sistate' + count).css("display", "block").val('');
html.find('input').val(''); // Clear input values in the cloned element
html.find('input#counter').val(count).prop("readonly", true);
html.find(".shipping-addr-div-change").html("<a class='btn btn-success waves-effect waves-light mr-1 shipping-addr-add-more'>+ Add More Shipping Address </a><a class='btn btn-danger waves-effect waves-light mr-1 shipping-addr-remove'>- Remove </a>");
html.insertAfter(".after-shipping-addr-add-more:last");
toggleButtons();
});
$("body").on("click", ".shipping-addr-remove", function() {
var rows = $(".after-shipping-addr-add-more");
if (rows.length > 1) {
$(this).parents(".after-shipping-addr-add-more").remove();
} else {
alert("At least one Shipping Address must be displayed.");
}
toggleButtons();
// if($('#addressCopiedAsShipping').is(':checked')){}
// else{ $('#addressCopiedAsShipping').prop("checked", false); }
});
function toggleButtons() {
var elementCount = $(".after-shipping-addr-add-more").length;
// console.log('elementCount == ' + elementCount);
if (elementCount > 1) {
$(".shipping-addr-remove").show(); // Show the "shipping-addr-remove" buttons
} else {
$(".shipping-addr-remove").hide(); // Hide the "shipping-addr-remove" buttons
}
$(".after-shipping-addr-add-more .shipping-addr-add-more").hide();
$(".after-shipping-addr-add-more:last .shipping-addr-add-more").show();
}
$('#submit-button').click(function() {
// Disable the button
$(this).prop('disabled', true);
// Change the button content to a spinner
$(this).html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> Loading...');
// Simulate a delay to demonstrate loading (you can replace this with your actual loading logic)
setTimeout(function() {
// Re-enable the button and restore the original text
$('#submit-button').prop('disabled', false);
$('#submit-button').html('Submit');
}, 3000); // Replace 3000 with the actual loading time in milliseconds
});
});
function changeFields(element) {
var selectedValue = $(element).val();
var elementId = $(element).attr('id');
var match = elementId.match(/\d+/);
if (match) {
var idnumber = parseInt(match[0], 10);
if (selectedValue == 'IN') {
$("#sdstate" + idnumber).show();
$("#sistate" + idnumber).hide();
} else {
$("#sdstate" + idnumber).hide();
$("#sistate" + idnumber).show();
}
} else {
// alert("No number found in the ID");
}
}
</script>
<script>
// document.getElementById('myForm').addEventListener('submit', function(event) {
// var form = event.target;
// // Check if form is valid
// if (!form.checkValidity()) {
// event.preventDefault(); // Prevent form submission
// form.reportValidity(); // Display validation error messages
// $('#submitBtn').prop('disabled', false); // Re-enable the button
// } else {
// $('#submitBtn').prop('disabled', true); // Disable the button to prevent duplicate submissions
// }
// });
document.getElementById('myForm').addEventListener('submit', function(event) {
var form = event.target;
// Check if form is valid
if (!form.checkValidity()) {
event.preventDefault(); // Prevent form submission
$('#submitBtn').prop('disabled', false); // Re-enable the button
// Display custom alert message
alert('Please ensure all required fields are filled out correctly');
} else {
$('#submitBtn').prop('disabled', true); // Disable the button to prevent duplicate submissions
}
});
</script>
<script>
function validateEmail(email) {
// Regular expression for a basic email validation
var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
var emailInput = document.getElementById("cmail");
var validationMessage = document.getElementById("emailValidationMessage");
if (emailPattern.test(email)) {
validationMessage.textContent = "";
} else if (email == "") {
validationMessage.textContent = "";
} else {
validationMessage.textContent = "Invalid email address";
validationMessage.style.color = "red";
}
}
function checkExisting(inputvalue,fieldname,elementid){
spanid = elementid == 'cmail' ? "emailValidationMessage" : "mobileValidationMessage";
if(spanid != ''){
var validationMessage = document.getElementById(spanid);
$.ajax({
type: "POST",
url: "<?= base_url() . 'check_existing' ?>",
data: {
value: inputvalue,
module: 'customers',
field: fieldname
},
success: function(response) {
if (response['data']['status']) {
validationMessage.textContent = response['data']['message'];
validationMessage.style.color = "red";
document.getElementById(elementid).value = "";
} else {
// validationMessage.textContent = "";
}
},
error: function() {
alert("Error occur.");
}
});
}
}
</script>
<script>
function restriction(event) {
var charCode = event.which || event.keyCode;
// Allow numeric values and backspace
if ((charCode >= 48 && charCode <= 57) || charCode === 8) {
var currentLength = document.getElementById('cmobile').value.length;
// Check if the length is within the desired range (10 to 15)
if (currentLength < 15 || charCode === 8) {
return true;
} else {
event.preventDefault(); // Prevent input when the maximum length is reached
return false;
}
} else {
event.preventDefault(); // Prevent the character from being entered
return false;
}
}
</script>