I need a password protected page that will work with multiple passwords (essentially Dealer IDs). To do this, I created a data collection with a Dealer ID field. Then, I created a form with a Dealer ID field. I added code to the page that is supposed to users to the password protected page IF their dealer ID matches one of the dealer IDs in the data collection.
I have been told that the code is correct; however, it’s not working. When I go to the live site, the default form submission message appears.
Here my code (Note: I’ve xxxxx out the URL since this is for a client). Any help that you can provide would be greatly appreciated!!!
import wixData from ‘wix-data’ ;
import wixLocation from ‘wix-location’ ;
$w . onReady ( function () {
$w ( “#wixforms1” ). onWixFormSubmitted (() => {
const enteredPassword = $w ( “#input2” ). value ;
console . log ( “Entered Password:” , enteredPassword );
checkPasswordValidity ( enteredPassword );
});
});
function checkPasswordValidity ( enteredPassword ) {
console . log ( “Checking Password:” , enteredPassword );
wixData . query ( “DealerIDs” )
. eq ( “DealerID” , enteredPassword )
. find ()
. then ( results => {
console . log ( “Query Results:” , results );
if ( results . items . length > 0 ) {
wixLocation . to ( “URLxxxxxxxxxx” );
} else {
// Password is not valid
// Display an error message or perform any desired action
console . log ( “Invalid password” );
}
})
. catch ( error => {
console . log ( “Error:” , error );
});
}