I’m having trouble sending form data to a webhook URL from my Vue application. Every time I try to submit the form, I get cross-origin policy errors.
Here’s my contact form setup:
<form @submit.prevent="handleSubmit()" class="form-container">
<input class="input-field" type="text" name="fullName" id="fullName" v-model="fullName" placeholder="Full Name" required>
<input class="input-field" type="email" name="userEmail" id="userEmail" v-model="userEmail" placeholder="[email protected]" required>
<input class="input-field" type="text" name="projectTitle" id="projectTitle" v-model="projectTitle" placeholder="Project Title" required>
<input class="input-field" type="url" name="projectUrl" id="projectUrl" v-model="projectUrl" placeholder="Project URL" required>
<textarea class="input-field" name="description" id="description" v-model="description" rows="4" placeholder="Tell us about your project..."></textarea>
<input class="input-field" type="text" name="linkedinHandle" id="linkedinHandle" v-model="linkedinHandle" placeholder="LinkedIn">
<input class="input-field" type="text" name="githubHandle" id="githubHandle" v-model="githubHandle" placeholder="GitHub">
<button class="submit-btn" type="submit">Send Application</button>
</form>
And here’s the Vue component handling the submission:
<script>
import axios from 'axios';
export default {
name: 'ApplicationForm',
data() {
return {
fullName: '',
userEmail: '',
projectTitle: '',
projectUrl: '',
description: '',
linkedinHandle: '',
githubHandle: ''
}
},
methods: {
handleSubmit() {
axios.post('hooks.zapier.com/hooks/catch/WEBHOOK_ID', {
fullName: this.fullName,
userEmail: this.userEmail,
projectTitle: this.projectTitle,
projectUrl: this.projectUrl,
description: this.description,
linkedinHandle: this.linkedinHandle,
githubHandle: this.githubHandle
})
.then((result) => {
console.log('Success:', result);
})
.catch((err) => {
console.log('Error:', err);
});
alert('Application submitted successfully!');
}
}
}
</script>
The browser console shows these errors:
Access to XMLHttpRequest blocked by CORS policy: Request header 'content-type' is not allowed by Access-Control-Allow-Headers in preflight response.
Access to XMLHttpRequest blocked by CORS policy: The request client is not a secure context.
How can I fix this cross-origin issue when sending data to the webhook endpoint?