I am working on a Vue application. I have a form with a button that, when clicked, should fill the input field with the value paypal
and then submit the form. However, when I check the variable $_POST['paymentMethod']
in the file test_form.php
, it shows as null
instead of paypal
. What could be causing this issue?
Below is the code I have implemented:
HTML:
<form action="test/test_form.php" method="POST" ref="form">
<button type="button" v-on:click="setMethod('cc')">Credit card</button>
<button type="button" v-on:click="setMethod('paypal')">Paypal</button>
<input type="text" name="paymentMethod" required v-model="selectedMethod">
</form>
Javascript:
new Vue({
el: "#app",
data: {
selectedMethod: null,
},
methods: {
// Set payment
setMethod: function(type) {
this.selectedMethod = type; // Filling the field here
this.$refs.form.submit(); // Submitting the form
},
}
});