I am trying to use Axios within Vue to POST data set by the user to PHP. I am creating a JSON object using PHP and want to add filtering it to the object. I created filtering inputs for the user to apply and I want to take those user inputs and pass the values to PHP using Axios.
So what I have so far is:
onSubmit () {
axios.post('http://website.com/index.php', {
'region': this.selectedRegion,
'jobType': this.selectedJobType,
'category': this.selectedCategory,
}).then(response => {
if (response.data.error) {
console.log('error', response.data.error)
} else {
this.postStatus = true;
console.log('success', response.data.message)
}
}).catch(error => {
console.log(error.response)
});
}
So the data variables of selectedRegion, selectedJobType, and selectedCategories are set in Vue based on what the user sets in the input. The user then would need to click a submit button to run the onSubmit function. The trouble I am having now is taking that data and adding it into PHP.
Edit: Trying to clarify I little more. I want to take the data from JS and then be able to output that data in PHP after it is posted.
Edit2: I tried adding:
<?php
if(isset($_POST['region'])) {
$region = $_POST['region'];
echo $region
}
?>
to the PHP file to output the region value, but that then gives me an error saying the variable is undefined