I'm not sure is there any other way to called two different axios URL which below is the code for submit function.
processSubmit(){
if(this.$refs.form.validate()){
this.ob_personal_document = this.$refs.ob_personal_document.files[0];
let formImage = new FormData();
formImage.append('ob_personal_document', this.ob_personal_document);
this.axios.post('ajaxfile.php', formImage,{
headers: {
'Content-Type': 'multipart/form-data'
}
}).then(function (response) {
if(!response.data){
alert('File not uploaded.');
}else{
alert("file is uploaded");
let formData = new FormData();
formData.append('ob_name', this.ob_name)
formData.append('ob_address', this.ob_address)
formData.append('ob_mobile',this.ob_country.countryCode + this.ob_mobile)
formData.append('ob_state', this.ob_state)
formData.append('ob_city', this.ob_city)
formData.append('ob_email', this.ob_email)
formData.append('ob_contact', this.ob_contact)
formData.append('ob_businesstype', this.ob_business_type)
formData.append('ob_country', this.ob_country.text)
formData.append('ob_payment', this.ob_payment)
formData.append('ob_halal', this.ob_halal)
formData.append('ob_acc_type', this.ob_acc_type)
formData.append('ob_bpname', this.ob_bpname)
formData.append('ob_RCno', this.ob_RCno)
formData.append('ob_document_type', this.ob_document_type)
formData.append('ob_license', this.ob_license)
formData.append('ob_ssm', this.ob_ssm)
formData.append('ob_person_name', this.ob_person_name)
formData.append('ob_ic_number', this.ob_ic_number)
formData.append('ob_passport', this.ob_passport)
formData.append('ob_personal_document', this.ob_personal_document.name)
formData.append('ob_original_address', this.ob_original_address)
var owner = {};
formData.forEach(function(value, key){
owner[key] = value;
});
this.axios({
method: 'post',
url: 'http://www.example.com/process.php?action=create',
data: formData,
config: {
headers: {
'Content-Type':
'multipart/form-data'
}}
}).then(function (response) {
console.log(response);
this.newOwner.push(owner);
});
alert("Completed process");
}
})
.catch(function (error) {
console.log(error);
});
} else {
alert("Its not validateed");
}
},
The result of this is the image is uploaded while the data information is not upload to phpMyadmin. What i really want is when i pressed the submit button which will run processSubmit() and then if the form is empty then the error message will be pop out. When it is validated then it will upload the document to file storage by sending to ajaxfile.php. After if it is successfully submitted, it will start sending those form information to phpMyadmin.
This two function are successfully run if it is separated. The reason why i want it to be in one functino is because i want it to validate the form while the image must be in png/jpg/pdf type then only it will submit the form.