hello, someone could help me with my page, what happens is that I created a button to log in to my page which is linked to an interactive window and in that interactive window insert 1 imput text and 1 button and what I want is that when I click it validate the information with the database and take me to the next page.
To create a login button that validates user information and redirects to another page, start by setting up a database to store user credentials, such as email and password, with proper permissions for secure access. Then, design a login form with input fields for the email and password and a button to submit the login. You can also add a text box to display error messages if the login fails. In Developer Mode, write a simple code to check if the entered credentials match any records in the database, and if successful, redirect the user to the next page. For security, ensure you hash the password and consider using Wix’s Members Area for added protection. Test everything to ensure it works seamlessly.
I hope this helps if not then we can provide further help by connecting on a meeting for better understanding of the problem .
I understand what you mean but what I want to do is that with just an imput box (in which I can log in only with an ID number) and a button (validate that this ID is already in the database) and if it is not in the database gives me a message that I must enter a valid one or that I register and I put this code but it does not work and does not validate or redirect me to the page.
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;
$w.onReady(() => {
$w(“#loginButton”).onClick(() => {
const enteredID = $w(“#idInput”).value.trim(); // Capture and clean the entered ID
// Check if the user entered an ID
if (!enteredID) {
$w("#errorMessage").text = "Please enter your ID.";
$w("#errorMessage").show(); // Show error message
$w("#successMessage").hide(); // Hide success message
return;
}
// Query the "Import560" database to verify the ID
wixData.query("Import560") // Ensure "Import560" is the correct ID of your database collection
.eq("cedula", enteredID) // Compare the "cedula" field with the entered value
.find()
.then((results) => {
if (results.items.length > 0) {
// If the ID is registered, redirect or show success
const user = results.items[0]; // First record found
$w("#successMessage").text = `Welcome, ${user.nombre}!`;
$w("#successMessage").show(); // Show success message
$w("#errorMessage").hide(); // Hide error message
// Redirect to another page within the site
wixLocation.to("/recycling-system"); // Change "recycling-system" to the correct SEO URL for your page
} else {
// If the ID is not registered, show an error message
$w("#errorMessage").text = "The entered ID is not registered.";
$w("#errorMessage").show(); // Show error message
$w("#successMessage").hide(); // Hide success message
}
})
.catch((error) => {
console.error("Error querying the database:", error);
$w("#errorMessage").text = "An error occurred. Please try again.";
$w("#errorMessage").show(); // Show error message
$w("#successMessage").hide(); // Hide success message
});
});
});
can we connect on a meeting to understand your problem better if you are interested .
yes, please but i dont speak very well english so you can speak slow pls