Apr 3rd 2024, 6:37:59
Broken email delete button.
Here's a headstart for you:
js portion (which will delete the message container in which you click delete on)
I'm not sure how you have your endpoints setup, but from looking at the ones for forward/reply I'd assume you'd have something like this:
Here's a headstart for you:
js portion (which will delete the message container in which you click delete on)
function deleteEmail(emailId) {
fetch(`/path/to/delete-email-endpoint.php?emailId=${emailId}`, {
method: 'DELETE',
})
.then(response => response.json())
.then(data => {
if (data.success) {
console.log(data.message);
const messageElement = document.getElementById(`msg${emailId}`);
if (messageElement) messageElement.remove();
} else {
console.error(data.error);
}
})
.catch(error => console.error('Error:', error));
}
I'm not sure how you have your endpoints setup, but from looking at the ones for forward/reply I'd assume you'd have something like this:
<?php
session_start();
$response = [];
if (!isset($_SESSION['user_id'])) {
$response['error'] = 'User not authenticated';
echo json_encode($response);
exit;
}
if ($_SERVER['REQUEST_METHOD'] === 'DELETE') {
parse_str(file_get_contents("php://input"), $delete_vars);
$emailId = $delete_vars['emailId'] ?? '';
if (empty($emailId) || !is_numeric($emailId)) {
$response['error'] = 'Valid Email ID is required';
} else {
if (deleteEmailById($emailId)) {
$response['success'] = true;
$response['message'] = 'Email deleted successfully';
} else {
$response['error'] = 'Failed to delete email';
}
}
} else {
$response['error'] = 'Invalid request method';
}
echo json_encode($response);
?>
Edited By: Slagpit on Apr 4th 2024, 6:01:35
See Original Post
See Original Post
Resistance is futile. You will be assimilated.