just remove the form tag then submit using ajax
Jan 26, 2017
5
Level 10
Submit a Vue Form with a Submit Button outside the form
Hi Guys , I have a form in VUE and I want submit this form with a button submit outsite the form .
Normaly I do like this -
<form method="POST" action="" @submit.prevent="destroyItem( SubmitMyForm )">
<input name="name" type="text" >
<button type="submit" class="btn btn-success" >Submit</button>
</form>
It works fine like this upon , but I want do something like this below -
<form method="POST" action="" id="myForm" @submit.prevent="destroyItem( SubmitMyForm )">
<input name="name" type="text" >
</form>
<button type="submit" class="btn btn-success" @click.this.myForm.submit >Submit</button>
I wold like to submit this form from a button outsite the form , does some one knows the best way to do this ? Thanks
Level 9
If you give the form an ID, or some other identifier, you could trigger the submit function of the element after fetching it.
document.getElementById("formId").submit();
3 likes
Please or to participate in this conversation.