Hi all,
I have filled in an input form and on submit, I would like to post the information captured into html form input elements which are hidden and are needed in order to send this information to an external site.
Here is the code that I have tried:
Page Code:
import {sendEmail, sendEmailWithRecipient} from 'backend/email';
import {fetch} from 'wix-fetch';
import wixData from 'wix-data';
$w.onReady(function () {
$w("#dataset1").onAfterSave(sendFormData);
$w('#button1').onClick(function () {
$w("#html1").postMessage($w("#input1").value, $w("#input2").value);
})
});
export function button1_onClick() {
// send message to the HTML element
console.log('The output of this function is $w("#input1").value, $w("#input2").value')
$w("#html1").postMessage($w("#input1").value, $w("#input2").value);
}
function sendFormData() {
const subject = `${$w("#input1").value} has just signed up`;
const body = `The following member has just signed up'
\rFirst Name: ${$w("#input1").value}
\rEmail: ${$w("#input2").value}`;
sendEmail(subject, body)
.then(response => console.log(response));
}
HTML code:
<html>
<body>
<Form name="makeCard" method="Post"
Action="">
<Input Type="Hidden" id="nme" Name="nme">
<Input Type="Hidden" id="eml" Name="eml">
<Input Type="Hidden" Name="bc" value="10384">
<Input Type="Hidden" Name="coname" value="Supadata Loyalty">
<input Type="Hidden" name="retpg" value="">
<input Type="Hidden" name="referenceID" value="Reference You Want To Be Returned">
</Form>
</body>
<Script type="text/javascript">
window.onmessage = (event) => {
if (event.data) {
let message1 = event.data.message1;
let message2 = event.data.message2;
document.getElementById("nme").innerHTML = message1;
document.getElementById("eml").innerHTML = message2;
}
document.makeCard.submit();
}
</Script>
</html>
The problem seems to lie in the fact that the html input elements "nme" and "eml" are not updating with the information that has been posted.
I feel like I'm really close and just missing something small, I'm fairly new to Wix so any help would be appreciated.
Kind regards,
Daniel