I have a small waiver form where I want the user to “sign” it with their exact first name + last name. On a post in the forum I copied the code to query the “Members/PrivateMembersData” to get the first/last name of the member. I first go into “My Account” and remove the last name. I then verify the record in my Members Data collection doesn’t have a value. I also check my record in the Contacts doesn’t have anything either. But, my code always somehow pulls a last name even though I don’t see it when I look at the values in my collection. How is this possible???
Take a look at the if clause that starts with the comment “// First make sure the name exists for the member”
Here’s my code:
// Submit button has been clicked
// Validate form fields
export function submitBtn_click(event) {
//Add your code for this event here:
console.log("Starting to submit")
let user = wixUsers.currentUser
let userId = user.id
let fieldErrors = [];
// First make sure the signature was entered
if ($w('#signature').value.trim().length <= 0) {
fieldErrors.push("The Signature is required.");
console.log(fieldErrors.join("\n"));
$w('#errorMsg').text = fieldErrors.join("\n");
$w('#errorMsg').show()
} else {
// Now, retrieve the user first/last name of the member
wixData.query("Members/PrivateMembersData")
.eq("_id", wixUsers.currentUser.id)
.find()
.then((results) => {
// check if the signature matches the name of the user
let fullName = results.items[0].firstName.trim() + ' ' + results.items[0].lastName.trim();
console.log("'", fullName, "'")
console.log(results.items.length)
console.log(results.items[0].firstName.trim())
console.log(results.items[0].lastName.trim())
console.log($w('#signature').value.trim().toUpperCase() === fullName.trim().toUpperCase())
// First make sure the name exists for the member
if ( (results.items[0].firstName.trim().length <= 0) || (results.items[0].lastName.trim().length <= 0) ) {
$w('#errorMsg').text = "You do not have a first and/or last name set up for your account. Please go to the " +
"'My Account' link on the left hand side member area menu first."
$w('#errorMsg').show()
} else if (!($w('#signature').value.trim().toUpperCase() === fullName.trim().toUpperCase())) {
// Now we have determined the name doesn't match the signature
fieldErrors.push("The Signature must match the first and last name exactly of the member.");
}
// Ok, do we show error message or success message
if (fieldErrors.length > 0) {
$w('#errorMsg').text = fieldErrors.join("\n")
console.log(fieldErrors.join("\n"));
$w('#errorMsg').show();
$w('#successMsg').hide();
} else {
$w('#signature').value = $w('#signature').value.trim()
$w('#successMsg').show();
$w('#errorMsg').hide();
}
})
}
Thanks for your help!