@mikemoynihan99 Question. Have tried this and works beautifully. Except…if entry is deleted from database, for some reason it still does not allow you to use form a second time. How can one fix that…it shouldn’t be able to find the email in database, so not sure why it is doing this. For some reason I am not yet getting the error text to load.
@jeff-haskins have you deleted the entry from the live database or from the sandbox ?
@mikemoynihan99 Both
@jeff-haskins insert this extra bit of code, what results does it log?
.then((results) => {
let allResults = results.totalCount;
console.log(allResults);//this should log 0 if they have never submitted a form before
let allItems = results.items;
console.log(allItems);
Let me say thanks for working thru this step by step. Helped the poster and me and others a great deal, I am sure
@mikemoynihan99 any certain spot to insert that code addition?
oh wait…duh, didn’t read it thru
@mikemoynihan99 Hmm…well either I did not get the add’l code inserted correctly, or ?? But still getting same result of being blocked.
@mikemoynihan99 I’ve beat the code around as much as possible, still getting same results.
import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
$w.onReady( function () {
if (wixUsers.currentUser.loggedIn) {
let user = wixUsers.currentUser;
console.log(user);
user.getEmail()
.then((email) => {
let userEmail = email;
console.log(userEmail);
//here we automatically set the email input to the logged in member’s email address
$w(“#emailInput”).value = userEmail
wixData.query(“formDatabase”) //change this to the name of your database
.eq("email", userEmail) //"email is the name of the field in your database, change as necessary"
.limit(1)
.find()
.then((results) => {
let allResults = results.totalCount;
console.log(allResults);//this should log 0 if they have never submitted a form before
let allItems = results.items;
//what items are be logged Jeff ???
console.log(allItems);
if (allResults > 0) {
console.log(“member submitted form(s) previously”);
$w(“#submitButton1”).disable(); //change the id of the button as necessary
$w(‘#errorText1’).show(‘FadeIn’); //change the id of error text as necessary, note you should set text to hidden on load in properties menu for the text
}
})
})
}
})
@mikemoynihan99 Yes, that is way I inserted the add’l. Block still occurring. Not sure what items to be logged…
@jeff-haskins look at a few videos on youtube to bring yourself up to speed on the basics, then follow the above steps
@mikemoynihan99 Hah…actually found issue. I had changed the email user input in form to read only…that created issue. Reason I changed is because with the current code, a person can actually just change the email in the input field and bypass the block. So code will need a way to make it so email can not be manually changed in form or there is way for parties to bypass.
@mikemoynihan99 Workaround…I put a transparent box over the input box so it can not be clicked/edited. Thanks for all the help, working fine now
This code no longer works. For some reason even though you populated the email field with a .value, it does not save the email to the database. If it doesn’t save the email called, then how will it know to restrict the form?
for this code to actually work you need to add the following.
$w ( ‘#dataset’ ). setFieldValue ( ‘email’ , $w ( ‘#input’ ). value );
//change dataset name and input to match your settings.