hi all!
i’m experiencing what i think it’s an encoding problem from the kirby side:
i’m sending a some data through a form
<form id="newsletter" method="post">
<input id="email" name="email" type="email" class="bd-b--main">
<input type="submit" name="submit" class="submit" value="Send">
<div class="honeypot">
<input id="website" type="website" name="website">
</div>
</form>
fetch the data and send it to a kirby api endpoint like this
function onsubmit (e) {
e.preventDefault();
var form = document.querySelector('form');
var bot = document.querySelector('.honeypot');
var formdata = new FormData(form);
var body = {};
formdata.forEach(function(value, key){
body[key] = value;
});
console.log(body);
if (formdata.get('website') !== '') {
console.log('hallo bot');
} else {
fetch('api/newsletter', {
method: 'POST',
mode: "same-origin",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(body)
}).then(function (res) {
res.json();
}).then(function (resp) {
console.log(resp);
}).catch(function (error) {
console.log('Error:', error);
});
}
}
kirby api file
kirby()->routes([
[
'method' => 'POST',
'pattern' => 'api/newsletter',
'action' => function() {
if(r::is('POST')) {
$mc_data = r::data();
// echo $mc_data = a:1:{s:47:"{"email":"work@andrefincato_info","website":""}";s:0:"";}
}
}
]
]);
am i over-encoding? if i try to decode i get nothing.
thanks for any hint!