Hi, I'm encountering an this error:
"An error occurred in one of afterSave callbacks TypeError: Cannot read property 'match' of undefined"
After sending a filled form I created.
It does save it to the database but it doesn't send an email.
In my page I have some fields, some mandatory and some not, and 2 upload button, one for resume (mandatory) and one for WritingSamplesPortfolio (not mandatory)
This is the code from the sendGrid.js:
import {fetch} from 'wix-fetch';
export function sendWithService(key, sender, recipient, subject, body) {
const url = "https://api.sendgrid.com/api/mail.send.json";
const headers = {
"Authorization": "Bearer " + key,
"Content-Type": "application/x-www-form-urlencoded"
};
const recipients = recipient.split(";").map( (x) => "to[]=" + x + "&" ).join("");
const data = `from=${sender}&${recipients}&subject=${subject}&text=${body}`;
const request = {
"method": "post",
"headers": headers,
"body": data
};
return fetch(url, request)
.then(response => response.json());
}
This is the code from email.jsw:
import {sendWithService} from 'backend/sendGrid';
export function sendEmail(subject, body, sender) {
const key = "#####key#####";
const recipient = "###myEmail####;#####anotherEmail####";
return sendWithService(key, sender, recipient, subject, body);
}
And this is the code from the actual page:
$w.onReady(function () {
$w("#positionField").value = $w('#dynamicDataset').getCurrentItem().title
});
export function button1_click(event) {
$w("#anchor1").scrollTo();
$w('#box2').show();
$w('#columnStrip2').show();
}
export function vectorImage1_click(event) {
$w('#box2').hide();
$w('#box1').show();
}
import {sendEmail} from 'backend/email';
$w.onReady(function () {
$w("#dataset1").onAfterSave(sendFormData);
function sendFormData() {
const convertRegex = new RegExp(/wix:document:\/\/v1\/([^\/]+)\/(.*)$/);
const item = $w("#dataset1").getCurrentItem();
const matcheResume = item.resume.match(convertRegex);
const matcheWritingSamplesPortfolio = item.writingSamplesPortfolio.match(convertRegex);
const resumeUrl = `docs.wixstatic.com/ugd/${matcheResume[1]}?dn=${matcheResume[2]}`;
// `docs.wixstatic.com/ugd/${matches[1]}?dn=${matches[2]}`;
const writingUrl = `docs.wixstatic.com/ugd/${matcheWritingSamplesPortfolio[1]}?dn=${matcheWritingSamplesPortfolio[2]}`;
const sender = $w("#emailField").value;
const subject = `${$w("#nameField").value} applying for ${$w("#positionField").value}`;
const body = `Name: ${$w("#nameField").value}
\rEmail address: ${$w("#emailField").value}
\rPhone number: ${$w("#phoneField").value}
\rAvailable starting date: ${$w("#dateField").value}
\rLinkedIn Profile link: ${$w("#linkedInField").value}
\rCover Letter: ${$w("#coverField").value}
\rResume: ${resumeUrl}
\rWriting samples or portfolio: ${writingUrl}`;
sendEmail(subject, body, sender)
.then(response => console.log(response));
}
});
this is the form
![](https://static.wixstatic.com/media/a27d24_04b35cc90d42404c989655dd6257faac~mv2.png/v1/fill/w_49,h_49,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/a27d24_04b35cc90d42404c989655dd6257faac~mv2.png)
Why is this happening????
Thanks in advance.
Same problem anyone help please
Same here. This sucks!! Wix please update us on this!!