Hi,
I am having a bit of trouble finding the right Wix API to do what I need to do. Here is the situation, I have dynamic profile page set up for the suppliers I have for my business. On each supplier page, there’s a contact form. Upon clicking the contact form, I’d like it to do the following:
- log the entries into a collection that’s only for the contact entries.
- send an email to the supplier with the information from the contact form.
What I am struggling right now is to pull the supplier email into the backend function I’ve set up for SendGrid to send the email. I tried getCurrentItem(), which returned every field related to a supplier, but when I tried getItems(), it returned 0, and I am not sure why. What would be the solution to call the email from the relevant database?
Thanks.
Hi @huangchingyun ,
assign getcurentitem() in to a variable and then use variable.emali / variable.fieldvalue foremail in the dataset
to get the email
Thanks! It works! I have further questions however, now that I am trying to get the code to work to send the email. I keep getting an error message about the email is invalid. And the code I use is as below:
import {sendEmail} from ‘backend/test’;
$w.onReady( () => {
$w(“#dynamicDataset”).onReady( () => {
let itemObj = $w(“#dynamicDataset”).getCurrentItem().email;
function sendFormData() {
const recipient = itemObj;
const subject = New consultation signup **from** ${$w("#input1").value}
;
const body = Name: ${$w("#input1").value} \rEmail: ${$w("#input2").value} \rPhone: ${$w("#input3").value}
;
sendEmail(subject, body)
.then(response => console.log(response));
}
} );
} );
If anyone knows where I am making mistakes, please do tell. Thanks!
Have you seen the SendGrid tutorials like this one here as you might be missing a line like this after your rPhone value and before sendEmail.
const recipient = $w("#email").value;