I created a Vue component that has several forms that can be submitted by the user. On submit, the form will send some data to my backend. The problem is that my backend needs to know which form was submitted, and this input doesn't depend on the user, so I added a hidden input so that when the user send the data, my backend can also know which type of form was submitted. I tried the following:
<template>
<div>
<div v-if="order=='total'">
<form @submit="formSubmit">
<input type="hidden" v-model="order_type" value="form1">
<input type="text" class="form-control" v-model="amount">
<br>
<input type="text" class="form-control" v-model="price">
<br>
<button class="btn btn-primary">BUY</button>
</form>
</div>
<div v-else-if="order=='partial'">
<input type="hidden" v-model="order_type" value="form2">
<input type="text" class="form-control" v-model="amount">
<br>
<input type="text" class="form-control" v-model="price">
<br>
<button class="btn btn-primary">BUY</button>
</form>
</div>
<br>
</div>
</template>
<script>
import axios from 'axios'
export default {
props:{
order:{
type:String,
default:'total'
},
},
mounted() {
console.log('Component mounted.')
},
data() {
return {
name: '',
description: '',
output: ''
};
},
methods: {
formSubmit(e) {
e.preventDefault();
let currentObj = this;
axios.post('MYURL', {
order_type: this.order_type,
price: this.price,
amount: this.amount
})
.then(function (response) {
currentObj.output = response.data;
})
.catch(function (error) {
currentObj.output = error;
});
}
}
}
</script>
The problem with this code is that order_type doesn't get sent with the form. I have read somewhere that Vue doesn't allow hidden values, so is there any other way to do this?