โ
Fixes Implemented
1. Client-Side Prevention (JavaScript)
// In leads.js - Global submission flag
window.isSubmitting = window.isSubmitting || false;
$(document).on('submit', '#lead-note-form, #lead-modal-note-form', function(e) {
if (window.isSubmitting) {
console.log('Preventing duplicate submission');
return false;
}
window.isSubmitting = true;
// AJAX submission with proper flag reset in success/error/complete callbacks
$.ajax({
// ... ajax settings ...
complete: function() {
window.isSubmitting = false; // Always reset flag
}
});
});
2. Server-Side Prevention (PHP)
// In Leads.php controller - Check for recent duplicate notes
public function add_note($lead_id) {
// Check for duplicate note in last 10 seconds
$this->db->where('rel_id', $lead_id);
$this->db->where('rel_type', 'lead');
$this->db->where('addedfrom', $staff_id);
$this->db->where('description', $description);
$this->db->where('dateadded >', date('Y-m-d H:i:s', strtotime('-10 seconds')));
$recent_note = $this->db->get(db_prefix() . 'notes')->row();
if ($recent_note) {
// Return success to prevent client retries
return;
}
// Proceed with normal note creation
}
3. Modal Refresh Handling
// In main.js - Reset submission flag when modal content is refreshed
function _lead_init_data(data, id) {
// ... existing modal setup ...
// Reset any existing form submission flags
if (typeof window.isSubmitting !== 'undefined') {
window.isSubmitting = false;
}
// Trigger event for leads.js reinitialization
$(document).trigger('app.lead-modal-loaded');
}