nhance/app/Views/insurer_basic_info.php

162 lines
6.6 KiB
PHP

<div class="tab-pane fade active show" id="general-q-tab">
<div class="row">
<div class="col-12">
<div class="card-body">
<form role="form" class="parsley-examples" method="post" id="insurer_general_form" enctype="multipart/form-data">
<input type="hidden" value="<?= csrf_hash() ?>" name="<?= csrf_token() ?>" />
<input type="hidden" name="PrimaryKey" id="insurer_General_PrimaryKey" value="<?= isset($insurer['id']) ? $insurer['id'] : '' ?>"/>
<input type="hidden" name="insurer_id" id="insurer_id" />
<div class="form-group">
<div class="form-row">
<div class="form-group col-md-4">
<label for="entity_type_id">Insurer Type <span class="text-danger">*</span></label>
<select class="form-control" id="type" name="type" required>
<option value="">Select Type</option>
<?php foreach ($types as $type): ?>
<option value="<?= $type->id; ?>" <?= isset($insurer['type']) && $insurer['type'] == $type->id ? 'selected' : ''; ?>>
<?= $type->name; ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group col-md-4">
<label for="insurer_name">Insurer Name<span
class="text-danger">*</span></label>
<input type="text" class="form-control" id="insurer_name"
placeholder="Enter Insurer Name" value="<?= isset($insurer['name']) ? $insurer['name'] : '' ?>" name="name" required>
</div>
<div class="form-group col-md-4">
<label for="short_name">Insurer Short Name<span
class="text-danger">*</span></label>
<input type="text" class="form-control" id="short_name"
placeholder="Enter Short Name" value="<?= isset($insurer['short_name']) ? $insurer['short_name'] : '' ?>" name="short_name" required>
</div>
</div>
<hr>
</div>
<div class="form-group text-right m-b-0">
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1"
id="btnSubmit">Submit</button>
<button type="button" class="btn btn-secondary waves-effect btnBack"
id="btnBack">Cancel</button>
</div>
</form>
</div>
</div> <!-- end col-->
</div>
</div>
<!-- end -->
<script>
$(document).ready(function () {
$("#insurer_general_form").submit(function(events) {
events.preventDefault();
// var isValid = validateForm();
var isValid = true;
jQuery.each(events.target, function(index, event) {
if (event.validity.valid) {
}else{
isValid = false;
}
});
var PrimaryKey = $('#insurer_General_PrimaryKey').val();
var form_action = '';
if (isValid) {
if(PrimaryKey === ''){
form_action = '<?= base_url("master/insurer/createpost"); ?>';
}else{
form_action = '<?= base_url("master/insurer/edit"); ?>';
}
var formData = new FormData($('#insurer_general_form')[0]);
var OptionsHTML1 = ''
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
$.ajax({
data: formData,
url: form_action,
type: "POST",
dataType: 'json',
processData: false,
contentType: false,
success: function(res) {
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}, 1000);
console.log(res);
$('#insurer_id').val(res.data.id);
$('#insurer_General_PrimaryKey').val(res.data.id);
$('#insurer_id_branch').val(res.data.id);
$('#insurer_branch_contacts_id').click();
$('#btnBranchAdd').show();
var message = "Insurer General Info";
toastr.success(message, 'Success');
// $.toast({
// text: 'Insurer General Info',
// heading: "Submitted Sucessfully",
// position: 'top-right',
// icon: 'success',
// bgColor: !1,
// });
},
error: function (xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
toastr.warning('Something Wrong!', 'warning');
}, 1000);
}
});
}
});
function validateForm() {
var isValid = true;
// Perform validation for each field
$('#insurer_general_form input, #insurer_general_form select').each(function() {
// Check for empty text inputs and selects
if ($(this).is('input[type="text"]') || $(this).is('select')) {
if ($.trim($(this).val()) == '') {
alert('Please fill in all fields');
isValid = false;
return false; // Exit the loop early
}
}
// Check for file inputs (assuming image files)
if ($(this).is('input[type="file"]')) {
var fileInput = $(this)[0];
if (fileInput.files.length === 0) {
alert('Please select an image file');
isValid = false;
return false; // Exit the loop early
}
}
});
return isValid;
}
});
</script>