Kalifast_Bug_Reporter/create_ticket_shortcode.php

105 lines
4.4 KiB
PHP

<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Kalifast Bug Reporter</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<div>
<style>
.kft_bug_reporter_config {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin-top: 50px;
}
.kft_bug_reporter_config form {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.kft_bug_reporter_config form div {
margin: 10px;
}
.kft_bug_reporter_config form div label {
margin-bottom: 5px;
}
.kft_bug_reporter_config form div input, .kft_bug_reporter_config form div textarea {
width: 300px;
padding: 10px;
border-radius: 5px;
border: 1px solid #000;
}
.kft_bug_reporter_config form div button {
padding: 10px;
border-radius: 5px;
border: 1px solid #000;
background-color: #000;
color: #fff;
cursor: pointer;
}
</style>
<script>
async function requestCore(module, library, action, parameters = false) {
let form = new FormData();
form.append("JSON", JSON.stringify(parameters));
let nounce_token = "<?php echo (wp_create_nonce('wp_rest')); ?>";
let settings = {
"url": `${location.origin}/index.php/wp-json/api/eisge/eisge_api/${module}/${library}/${action}?_wpnonce=${nounce_token}`,
"method": "POST",
"timeout": 0,
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};
return JSON.parse(await $.ajax(settings));
}
document.addEventListener("DOMContentLoaded", async function(event) {
document.getElementById("kft_bug_reporter_form").addEventListener("submit", async function(event) {
event.preventDefault();
let response = await requestCore("Kalifast_Bug_Reporter", "Reporter", "post_kalifast_ticket", {
"title": document.getElementById("kft_bug_reporter_title").value,
"content": document.getElementById("kft_bug_reporter_content").value,
"contact": document.getElementById("kft_bug_reporter_contact").value
});
if (response.success) {
alert("Your ticket has been created");
} else {
alert("An error occured");
}
});
});
</script>
<div class= "kft_bug_reporter_config">
<h2>Report a bug</h2>
<form id="kft_bug_reporter_form">
<div>
<label for="kft_bug_reporter_title">Title</label>
<input type="text" id="kft_bug_reporter_title" name="kft_bug_reporter_title" required>
</div>
<div>
<label for="kft_bug_reporter_contact">Contact</label>
<input type="text" id="kft_bug_reporter_contact" name="kft_bug_reporter_contact" required>
</div>
<div>
<label for="kft_bug_reporter_content">Content</label>
<textarea id="kft_bug_reporter_content" name="kft_bug_reporter_content" required></textarea>
</div>
<div>
<button type="submit">Send</button>
</div>
</form>
</div>
</div>
</body>
</html>