I'm trying to send form data from Vue Resource to my PHP page. I can see it displayed on the PHP page but when I send it back as JSON I get an empty response. Why is it sending an empty response?
Edit:
It looks like the problem is that the value for the submit button is not set in PHP. I am not sure why that is happening. Tried using $_REQUEST
and axios/$.post
but it makes no difference.
PHP:
if(isset($_POST['submit']){
echo json_encode($_POST);
}
JS:
this.$http.post('addalbum.php', new FormData($('#submitalbum')))
.then(data => console.log(data));
HTML:
<form class="col s12" id="submitalbum" method="post" action="addalbum.php">
<div class="row">
<div class="input-field col s6">
<input name="artist" placeholder="Artist" type="text">
</div>
<div class="input-field col s6">
<input name="title" placeholder="Title" type="text">
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input name="genre" placeholder="Genre">
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input id="released" type="number" name="released" placeholder="Year Released">
</div>
<button @click.prevent="addNewAlbum" name="submit" class="waves-effect waves-light btn">Submit</button>
</div>
</form>