EVOLUTION-NINJA
Edit File: edit_institution.php
<?php $institution_id = isset($_GET['institution_id']) ? $_GET['institution_id'] : null; ?> <?php echo view('includes/admin_header.php') ?> <div class="content-wrapper"> <div class="col-sm-12 col-md-offset-1 col-md-10 col-lg-offset-1 col-lg-10"> <section class="content-header"> <br> <a href="javascript:history.back()" class="btn btn-primary" style="float: right;">Back</a> </section> <br> <br> <section class="content enrolled_details" style="margin-left: 15%; width: 100%;"> <div class="row" style="margin:0 !important;"> <div class="col-sm-6"> <h2 style="margin-left: 35%;">Edit Institution Details</h2> <form id="main_form" class="form-horizontal"> <!-- Add a hidden input field to capture the institution ID --> <input type="hidden" name="institution_id" value="<?= isset($_GET['institution_id']) ? htmlspecialchars($_GET['institution_id']) : '' ?>"> <!-- Input fields to edit institution data (similar to your previous code) --> <div class="form-group"> <label class="control-label col-sm-4" for="institution_name">Institution Name</label> <div class="col-sm-8 enrolled"> <input type="text" class="institu_name" name="institution_name" id="institution_name" value="<?= isset($_GET['institution_name']) ? htmlspecialchars($_GET['institution_name']) : '' ?>" /> </div> </div> <div class="form-group"> <label class="control-label col-sm-4" for="address">Address</label> <div class="col-sm-8 enrolled"> <input type="text" class="institu_name" name="address" id="address" value="<?= isset($_GET['address']) ? htmlspecialchars($_GET['address']) : '' ?>" /> </div> </div> <div class="form-group"> <label class="control-label col-sm-4" for="email">Email</label> <div class="col-sm-8 enrolled"> <input type="text" class="institu_name" name="email" id="email" value="<?= isset($_GET['email']) ? htmlspecialchars($_GET['email']) : '' ?>" /> </div> </div> <div class="form-group"> <label class="control-label col-sm-4" for="phone">Phone</label> <div class="col-sm-8 enrolled"> <input type="text" class="institu_name" name="phone" id="phone" value="<?= isset($_GET['phone']) ? htmlspecialchars($_GET['phone']) : '' ?>" /> </div> </div> <div class="form-group"> <label class="control-label col-sm-4" for="contact_person_details">Contact Person Details</label> <div class="col-sm-8 enrolled"> <input type="text" class="institu_name" name="contact_person_details" id="contact_person_details" value="<?= isset($_GET['contact_person_details']) ? htmlspecialchars($_GET['contact_person_details']) : '' ?>" /> </div> </div> <!-- Update button to save changes --> <div class="form-group"> <div class="col-sm-8 col-sm-offset-4"> <button type="submit" class="btn btn-primary updateb">Update</button> </div> </div> </form> </div> </div> </section> </div> </div> <?php echo view('includes/admin_footer.php') ?> <script> $(document).ready(function() { $("#main_form").on('submit', function(e) { e.preventDefault(); var phoneNumber = $("#phone").val(); var email = $("#email").val(); // Phone number validation (exactly 10 digits) if (!/^\d{10}$/.test(phoneNumber)) { toastr.error("Phone number should be filled with 10-digits."); return; } // Email validation if (!/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/.test(email)) { toastr.error("Please enter a valid email address."); return; } $.ajax({ url: "<?php echo site_url('update-institution') ?>", type: 'POST', data: $(this).serialize(), success: function(response) { if (response.success) { console.log("Institution information updated successfully."); toastr.success("Institution information updated successfully."); var url = "<?php echo base_url('view');?>"; url += "?institution_name=" + $("#institution_name").val(); url += "&address=" + $("#address").val(); url += "&email=" + email; url += "&phone=" + phoneNumber; url += "&contact_person_details=" + $("#contact_person_details").val(); url += "&id=" + response.id; window.location = url; } else { console.log("Failed to update institution information."); toastr.error(response.message); } }, error: function(error) { console.log("AJAX request error"); console.log(error); } }); }); }); </script> <style> .form-horizontal .control-label{ text-align: right !important; position: relative; top: 10px; } .institu_name{ width: 125%; height: 37px; padding: 10px; border-radius: 5px; } .sub-institution { width: 50%; /* margin-left: 247PX; margin-top: 60PX; */ } .clear_bttn{ margin-left: -135px; } .sub-institution-width{ width: 50%; } .content-wrapper{ background-image: url('public/assets/website_assets/images/banner.png'); } </style>