Input variables in href

Background: I am sending email notifications on form submittal. The wix documentation ( https://support.wix.com/en/article/how-to-send-an-email-on-form-submission ) is very helpful, but sends the email only in text format. Tal has a write-up that shows how to easily send the emails in html format: https://www.wix.com/code/home/forum/questions-answers/how-to-design-my-email-notification . This is great, because now the email notifications can look attractive and professional.

However, I have another challenge now. I haven’t figured out how to include my wix input variables (e.g. ${$w(“#input1”).value} ) within an href. For example, I want to set up a link to direct respondents to a website based on certain input variables.

This, for example, does not work (the offending code is bolded):

import {sendEmail, sendEmailWithRecipient} from ‘backend/email’;
$w.onReady(function () {
$w(“#dataset1”).onAfterSave(sendFormData);
});
function sendFormData() {
const subject = Welcome;

const body = Please visit your page on our website. <a href="https://www.xxxxxx.com/to/m5pMOI?firstname=${$w("#input1").value}&lastname=${$w("#input2").value}">click here</a>;

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

Does anyone know the solution?
Thanks!

Hi,
Can you tell what error do you get? How looks the email content?

Can you try put your value in external variables and use them in href?
Maybe try to print them to the console in order to see the if values are valid.

What I mean is something like this:

const var1 = $w("#input1").value
const var2 = $w("#input2").value
console.log('var1=', var1)
console.log('var2=', var2)
const body = `Please visit your page on our website. 
<a href="https://www.xxxxxx.com/to/m5pMOI?firstname=${var1}&lastname=${var2}">
click herevar1
</a>`;

This should help us be more specific and figure out where the problem is