import wixData from 'wix-data';
import wixCRM from 'wix-crm-backend';
$w.onReady(function () {
$w('#submitBtn').onClick(function () {
const signatureValue = $w('#signatureInput').value;
const pageTitle = $w('#pageTitle').text; // Assuming you have an element with an ID 'pageTitle' to capture the page title.
// Submit to Wix CRM
wixCRM.createContact({
"emails": [{ "tag": "work", "email": "nutechsupreme@gmail.com" }], // Replace with the desired email address
"name": "Signature Submission",
"contactInfo": { "Signature": signatureValue, "Page Title": pageTitle },
"allowDuplicates": false
})
.then((contactId) => {
sendEmailWithSignature(signatureValue, pageTitle);
$w('#successMessage').show(); // Assuming you have an element with an ID 'successMessage' to show a success message after submission.
$w('#signatureInput').disable(); // Disable the signature input after submission.
})
.catch((error) => {
console.error('Error creating contact: ', error);
// Handle error if necessary.
});
});
});
function sendEmailWithSignature(signatureValue, pageTitle) {
const subject = 'New Signature Submission';
const body = `Signature: ${signatureValue}\nPage Title: ${pageTitle}`;
wixCRM.emailContact('nutechsupreme@gmail.com', {
"subject": subject,
"body": body
})
.then(() => {
// Email sent successfully, do any additional actions if needed.
// For example, display a success message or redirect to another page.
})
.catch((error) => {
console.error('Error sending email: ', error);
// Handle error if necessary.
});
}