I am new to JavaScript, so please excuse any mistakes in my code. I am working on a form that utilizes AWS SNS to send an email to my company with the data submitted through the form. The issue I'm facing is that there is no feedback for the user after they submit the form.
I have been attempting to use VueJS to redirect to another page or URL displaying a message like "Thank you. Your form has been submitted," but I keep encountering an error message saying "Cannot read property 'push' of undefined."
Ideally, I would like to use "this.router.push('abc123.com');" to automatically redirect to abc123.com after the form submission.
Any assistance you can provide will be greatly appreciated!
const routes = [
{ path: 'abc123.com'}
]
const router = new VueRouter({
routes
})
var app = new Vue({
el: '#app',
router,
data(){
return{
yourName: null,
from: null,
phone: null,
company: null,
msg: null,
timeframe: '',
picked: '',
proType: ''
}
},
methods: {
checkForm: function (){
console.log(this.fullName);
let result = null;
let that = this;
if ( this.from === null || this.from === '' ){
alert( "Please enter a valid email address." )
return false;
}
if ( this.yourName === null || this.yourName === '' ){
alert( "Please enter your full name." )
return false;
}
if ( this.msg === null || this.msg === '' ){
alert( "Please enter a message." )
return false;
}
if ( this.picked === null || this.picked === '' ){
alert( "Please choose a contact option." )
return false;
}
if ( this.timeframe === null || this.timeframe === '' ){
alert( "Please choose a time frame for the project." )
return false;
}
if ( this.proType === null || this.proType === '' ){
alert( "Please choose whether this is a new project or if it will be a modified application." )
return false;
}
that.publishSNS();
that.redirect();
},
publishSNS: function(){
//Removed confidential information for post
});
var sns = new AWS.SNS();
var d = new Date();
var params = {
Message: "Name: " + this.yourName + "\n" + "Company: " + this.company + "\n" + "Email: " + this.from + "\n" + "Phone Number: " + this.phone + "\n" + "Project Type: " + this.proType + "\n" + "Contact by: " + this.picked + "\n" + "Time Frame: " + this.timeframe + "\n" + "Message: " + this.msg,/* required */
Subject: 'Proposal Request' + ' (sent ' + d + ')',
};
sns.publish(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
},
redirect: function(){
this.router.push('https://360works.com/action/email');
}
}
}).$mount('#app')
Upon form submission, the browser should navigate to abc123.com.