Adapt the following code to my form that includes 11 photo uploads and is sent to my email. It works!
But the problem I have is that when a user uploads less than 11 photos, the email is not sent. In other words, for the email to be sent, all 11 photos must be uploaded. Is there any way to modify the code so that the email is sent with the links of all the photos that the user wants?
Any ideas? I would be very grateful if you could help me.
//sendgrid script
import {sendEmail, sendEmailWithRecipient} from ‘backend/email’;
//send form data
$w.onReady(function () {
$w(“#dataset2”).onAfterSave(sendFormData);
});
function sendFormData() {
}
export function text68_viewportEnter(event) {
const item = $w(“#dataset2”).getCurrentItem();
const wiximageurl = “https://static.wixstatic.com/media/”;
// RECOVER UPLOADED IMAGE URL 1
let image1local = “”;
image1local = item.payStub1.replace(‘image://v1/’, ‘’);
image1local = image1local.substr(image1local.lastIndexOf(‘/’)+1);
const image1Url = wiximageurl + image1local;
// RECOVER UPLOADED IMAGE URL 2
let image2local = “”;
image2local = item.payStub2.replace(‘image://v1/’, ‘’);
image2local = image2local.substr(image2local.lastIndexOf(‘/’)+1);
const image2Url = wiximageurl + image2local;
// RECOVER UPLOADED IMAGE URL 3
let image3local = “”;
image3local = item.payStub3.replace(‘image://v1/’, ‘’);
image3local = image3local.substr(image3local.lastIndexOf(‘/’)+1);
const image3Url = wiximageurl + image3local;
// RECOVER UPLOADED IMAGE URL 4
let image4local = “”;
image4local = item.payStub4.replace(‘image://v1/’, ‘’);
image4local = image4local.substr(image4local.lastIndexOf(‘/’)+1);
const image4Url = wiximageurl + image4local;
// RECOVER UPLOADED IMAGE URL 5
let image5local = “”;
image5local = item.payStub5.replace(‘image://v1/’, ‘’);
image5local = image5local.substr(image5local.lastIndexOf(‘/’)+1);
const image5Url = wiximageurl + image5local;
// RECOVER UPLOADED IMAGE URL 6
let image6local = “”;
image6local = item.payStub6.replace(‘image://v1/’, ‘’);
image6local = image6local.substr(image6local.lastIndexOf(‘/’)+1);
const image6Url = wiximageurl + image6local;
// RECOVER UPLOADED IMAGE URL 7
let image7local = “”;
image7local = item.payStub7.replace(‘image://v1/’, ‘’);
image7local = image7local.substr(image7local.lastIndexOf(‘/’)+1);
const image7Url = wiximageurl + image7local;
// RECOVER UPLOADED IMAGE URL 8
let image8local = “”;
image8local = item.payStub8.replace(‘image://v1/’, ‘’);
image8local = image8local.substr(image8local.lastIndexOf(‘/’)+1);
const image8Url = wiximageurl + image8local;
// RECOVER UPLOADED IMAGE URL 9
let image9local = “”;
image9local = item.payStub9.replace(‘image://v1/’, ‘’);
image9local = image9local.substr(image9local.lastIndexOf(‘/’)+1);
const image9Url = wiximageurl + image9local;
// RECOVER UPLOADED IMAGE URL 10
let image10local = “”;
image10local = item.payStub10.replace(‘image://v1/’, ‘’);
image10local = image10local.substr(image10local.lastIndexOf(‘/’)+1);
const image10Url = wiximageurl + image10local;
//// RECOVER UPLOADED IMAGE URL ID
let imageIDlocal = “”;
imageIDlocal = item.identification.replace(‘image://v1/’, ‘’);
imageIDlocal = imageIDlocal.substr(imageIDlocal.lastIndexOf(‘/’)+1);
const imageIDUrl = wiximageurl + imageIDlocal;
const subject = (𝗩𝗮𝗹𝗽𝗮𝗿 𝗕𝘂𝘀𝗶𝗻𝗲𝘀𝘀) - 𝗥𝗲𝗾𝘂𝗲𝘀𝘁 𝗙𝗼𝗿 𝗘𝗺𝗽𝗹𝗼𝘆𝗺𝗲𝗻𝘁 𝗩𝗲𝗿𝗶𝗳𝗶𝗰𝗮𝘁𝗶𝗼𝗻 - ${$w("#input34").value}
;
const body = `𝗥𝗘𝗤𝗨𝗘𝗦𝗧 𝗙𝗢𝗥 𝗘𝗠𝗣𝗟𝗢𝗬𝗠𝗘𝗡𝗧 𝗩𝗘𝗥𝗜𝗙𝗜𝗖𝗔𝗧𝗜𝗢𝗡 ${$w(“#input35”).value}
\rEmployer Date: ${$w(“#datePicker3”).value}
\rTo: ${$w(“#input1”).value}
//UPLOAD DOCUMENTATION
\rpay stub 1: ${image1Url}
\rpay stub 2: ${image2Url}
\rpay stub 3: ${image3Url}
\rpay stub 4: ${image4Url}
\rpay stub 5: ${image5Url}
\rpay stub 6: ${image6Url}
\rpay stub 7: ${image7Url}
\rpay stub 8: ${image8Url}
\rpay stub 9: ${image9Url}
\rpay stub 10: ${image10Url}
// UPLOAD ID
\rID : ${imageIDUrl}`;
sendEmail(subject, body)
.then(response => console.log(response));
}