Display clicked datas within SendGrid email notification

Hi!
I made a form with Corvid which contains two types of data: https://www.bhenv.fr/demande-isolation

The clicked ones, for example if the visitor clicks on “Yes” I would like the email contains this data;
The input ones : name, first name, postcode and phone.

So far, I’m having an issue because I cannot find how to integrate the clicked data (= text on button so “Yes” in that case) into the body of the email sent after submission.

Here is my code:

import wixCRM from ‘wix-crm’;
import wixLocation from ‘wix-location’;
import wixData from ‘wix-data’;
import wixUsers from ‘wix-users’;
import {sendEmail} from ‘backend/email’;

let userId = wixUsers.currentUser.id;
$w.onReady(() => {
let toSave = {_id: userId};
$w(“#button3, #button4”).onClick(event => {
switch (event.target.id){
case “button3”:
toSave.maisonIndividuelle = “oui”;
$w(‘#group4’).hide();
$w(‘#group9’).show();
break ;
}
})

$w.onReady( function () {
$w(“#dataset1”).onAfterSave(sendFormData);
});

function sendFormData() {
const subject = Nouveau lead : ${$w("#input1").value};
const body = Informations du lead : Nom : ${$w("#input1").value} Prénom : ${$w("#input2").value} Code postal : ${$w("#input5").value} Téléphone : ${$w("#input6").value};

sendEmail(subject, body)
.then(response => console.log(response));
}
})

Thanks for your help.

@yisrael-wix You seem to be the guy who could help me on that :slight_smile:

You say the email fails to send/doesn’t include the desired data but haven’t provided the code that sends the email. That appears to live in backend/email.

Have you also double checked that these inputs retain their value after the form is saved? They’re not reset? Verify you’re actually sending correct data to sendEmail with console.log.

The email is sending correctly but only with the #input datas while I would like to add the datas from clicked buttons.

The buttons used are not from “User datas” category so I cannot connect them properly to my dataset.

In the frontend I am looking for a way to integrate the datas from clicked buttons (“Yes” or “No”)
in the body of my email, along with the #input datas.

It seems that maybe I should not use the dataset connection and go only with code.

So saving clicked button data and input datas in the database.
Then sending email with those datas.