Sorry for making a second question for a previous one, but I didn’t get the help I needed. So, I want to make a form that a user can enter their name into and once they click the “Submit” button, the button would disable and disallow the same user to enter again.
When I previously asked, I received code to enter into the page. However, the button would not disable ONLY if it was connected to a dataset. But when I just put a normal button, it disables. I don’t know code so help would be much appreciated.
I’m trying to make a raffle-type form, so that people can enter it but only once.
Hello again.
You could simply disable the SUBMIT-BUTTON after someone has filled the form and pressed onto the button.
This does not work, as I previously stated. When you click the button it does not disable it at all. It will only disable a button that isn’t connected to a data set. (Yes I have the disable button code placed).
Then this example will be what you are searching for…
https://russian-dima.wixsite.com/meinewebsite/oneway-ticket
import wixData from 'wix-data';
import wixUsers from 'wix-users';
var userID, userEmail
$w.onReady(function () { getUserInfo() });
export function button1_click(event) {check_User()}
// This function will check, if the user is is already in your database (already has filled the form once).
function check_User (parameter) {console.log("Check-process started.")
wixData.query("OneWayTicket") //<---------- here the name of your DATABASE
.eq("title" ,userID) //<---- choose here the right reference-field (colum) do not touch userID.
.find()
.then( (results) => {
if(results.items.length > 0) {console.log("USER-Found in DATABASE")
console.log(userID)
console.log(userEmail)
$w('#box1').show()
//here your code............. if user has already filled the form once.......
} else {console.log("This USER do not exist yet in your DATABASE.")
//here your code............. if user has never filled the form.......
//Saving process to save the new user in DATABASE
let toInsert = {
"title": userID,
"firstName": $w('#input1').value,
"lastName": $w('#input2').value,
"eMail": $w('#input3').value,
};
wixData.insert("OneWayTicket", toInsert)
.then( (res) => {
console.log(res.items)
console.log("New User-Data saved.")
// here your CODE to disable BUTTON after the user was added to the DATABASE.
$w('#button1').disable()
$w('#input1').value = ""
$w('#input2').value = ""
$w('#input3').value = ""
} )
}
} )
.catch( (err) => {
let errorMsg = err;
} );
}
// This function will get Users-Informations (ID / e-Mail / log-in-state / )
function getUserInfo (parameter) {
let user = wixUsers.currentUser;
userID = user.id; // "r5cme-6fem-485j-djre-4844c49"
let isLoggedIn = user.loggedIn; // true
user.getEmail()
.then( (email) => {
userEmail = email; // "user@something.com"
} );
console.log("User-Info loaded.")
console.log("-----------------")
}
export function close_click(event) {
$w('#box1').hide()
}
@russian-dima
Hey! So, it works but if you refresh the page they can enter their details again and if they click the input boxes (like name) it enables the button again and they can send their entry again.
Here’s the code. I’m not sure what I did wrong, but please feel free to look and tell me if there’s anything I did wrong. I did delete some fields, but I’m not sure if that affects anything.
$w.onReady(function () { getUserInfo() });
export function enter1_click(event) { check_User() }
// This function will check, if the user is is already in your database (already has filled the form once).
function check_User(parameter) {
console.log("Check-process started.")
wixData.query("test2") //<---------- here the name of your DATABASE
.eq("forumDiscordName", userID) //<---- choose here the right reference-field (colum) do not touch userID.
.find()
.then((results) => {
if (results.items.length > 0) {
console.log("USER-Found in DATABASE")
console.log(userID)
console.log(userEmail)
$w('#box8').show()
//here your code............. if user has already filled the form once.......
} else {
console.log("This USER does not exist yet in your DATABASE.")
//here your code............. if user has never filled the form.......
//Saving process to save the new user in DATABASE
let toInsert = {
"title": userID,
"forumDiscordName": $w('#input1').value,
"userEmail": $w('#input2').value,
};
wixData.insert("test2", toInsert)
.then((res) => {
console.log(res.items)
console.log("New User-Data saved.")
// here your CODE to disable BUTTON after the user was added to the DATABASE.
$w('#enter1').disable()
$w('#input1').value = ""
$w('#input2').value = ""
})
}
})
.catch((err) => {
let errorMsg = err;
});
}
// This function will get Users-Informations (ID / e-Mail / log-in-state / )
function getUserInfo(parameter) {
let user = wixUsers.currentUser;
userID = user.id; // "r5cme-6fem-485j-djre-4844c49"
let isLoggedIn = user.loggedIn; // true
user.getEmail()
.then((email) => {
userEmail = email; // "user@something.com"
});
console.log("User-Info loaded.")
console.log("-----------------")
}
export function close_click(event) {
$w('#box8').hide()
}
@claritylove67
Hey! So, it works but if you refresh the page they can enter their details again and if they click the input boxes (like name) it enables the button again and they can send their entry again.
Then you have done something wrong.
Look at this pic. This happens when i am trying to to insert the same data.
The integrated function does not allow to insert data from the same user again.
It allows just once. And you can refresh as often as you want, it will show this warning.
You have of course tomodify your database, to get this to work.
Your database should look like this…
Test my code on my example (test-site) and you will see, that you will be able to fill the form just once.
@russian-dima I’m honestly lost for words. Everything I do just doesn’t seem to work. I’m sorry for the inconvenience I’ve caused, but it’s just not working. I’ve copied your code 5 times now and edited it. I’m going to try and make a look-alike to yours and see if maybe that works, along with making a new data-set and use a preset form. Also, for the box, that also doesn’t work. It doesn’t hide the box or show it when data is entered. 
-UPDATE- I made it look EXACTLY as yours does and now it doesn’t even disable the button.
@claritylove67
ok
You will find some more informations on my page.
@russian-dima I’m not sure what’s funny? I have the code exactly how yours is. I’ve connected the input boxes with the database and everything like you’re suppose to. The box part of the code doesn’t work at all, as I previously said. I set the values as the ones in the data-set, and like I’ve said multiple times it doesn’t work. I don’t understand why it’s not working when everything is the same as yours.
“More information on my page”, your page only contains the test form and code. Nothing very informative about that. Maybe explain where to input the code? (Page or Site, I used Page), how to create the box and make it interactive as yours is on the site because it doesn’t work lol. I’m not trying to give you a hard time, it’s just genuinely not working.
@claritylove67
Did you found the CHAT ?
What is the step by step instruction on how to end the code?