Hello! Please does anyone know how to disable a form from being submitted after a member has submitted it? That is, the member should only be allowed to submit it once. I tried a certain code I saw in this forum, no luck. Looked for videos, no luck.
Second question will be → Do you use DATASETS, oder do you use the Wix-Data-API (by code).
When you generate a SUBMISSION-PROCESS, you always and up to save something into your DATABASE.
And the exact way, of how your saving-process is conctructed is a very important information to be known, before anyone can tell you what is the problem on your page.
Where is the description of your setup?
Where is your used code?
Or even where is a pic of your SETUP?
All info what is given is that there is a SUBMIT-BUTTON which starts a SUBMISSION of a FORM.
If it helps you to know, hoch to disable a BUTTON, take a look here…
Thanks. I know about this disable code, but it enables again once the page is refreshed. How do I solve it, plus, is there any way you can break this lengthy info down into easier, lame-man language? I started the coding a few days ago and I’ve learnt a lot since then, but I’m still learning.
Ok, let’s say you are using the following elements…
you have a DATABASE
you use a dataset (for sure you use a dataset)
you use a CUSTOM-FORM
on your form you will have some INPUT-FIELDS
next or under your form you will have a SUBMIT-BUTTON
AND YOU DID NOT CONNECT ALL THE ELEMENTS INSIDE THE WIX-PROPERTIES-PANEL!!! → BECAUSE WE ARE GOING TO CODE IT!!!
THE ONLY CONNECTION YOU WILL SETUP is between → your DATABASE —> and your DATASET. This will be the only existing connection.
Your dataset will be named as → “#dataset1”
FIRST-PART-CODE:
$w.onReady(function() {console.log("PAGE is READY!");
$w('#dataset1').onReady(()=>{console.log("DATASET is READY!");
$w("#btnSubmit").onClick((event)=>{console.log(event.target.id+"-has been clicked!");
$w("#dataset1").save()
.then((item) => {
let fieldValue = item.fieldName; console.log(fieldValue);
}).catch((err) => {console.log(err);});
$w("#dataset1").setFieldValues({
"title": "New Title", //<---REPLACE HERE WITH YOUR OWN DATA (FIELD / VALUE)
"name": "New Name" //<---REPLACE HERE WITH YOUR OWN DATA (FIELD / VALUE)
});
});
});
$w('#dataset1').onBeforeSave(()=>{
$w("#dataset1").add()
.then(()=> {console.log("New item added");})
.catch((err)=> {console.log(err);});
});
$w('#dataset1').onAfterSave(()=>{
//What shall happen when data was saved ?
});
});
Try first to make this code work on your page.
Rename and replace all ElementIDs and modify them by your needs (orange marked)!
Also change DB-FIELD and DB-Value to your own setup…(red-marked)!
In your case, your data will come from INPUT-FIELDS, since you try to generate a SUBMISSION-FORM (a Form has always some kinf of INPUTS → Text-Inputs, DropDown-Inputs, Selection-Tag-Inputs and so on…)
So let’s say you want to save…
First-Name → DB-Field-ID inside your DATABASE = “firstName”
Last-Name → DB-Field-ID inside your DATABASE = “lastName”
e-Mail
of the current user, who is using your form.
You will have then first to set the right fields and field-values…
And here you defined the 3 wished DB-Values you want to save.
These 3-elements will be out INPUT-ELEMENTS (TEXT-INPUT), which will get the entered VALUE of the USER and set them to be saved later.
In total, your CODE should now look similar to this one…
$w.onReady(function() {console.log("PAGE is READY!");
$w('#dataset1').onReady(()=>{console.log("DATASET is READY!");
$w("#btnSubmit").onClick((event)=>{console.log(event.target.id+"-has been clicked!");
$w("#dataset1").save()
.then((item) => {console.log("ITEM: ", item);
let fieldValue = item.fieldName; console.log(fieldValue);
}).catch((err) => {console.log(err);});
$w("#dataset1").setFieldValues({
"firstName": $w('#inpFirstName').value,
"lastName": $w('#inpLastName').value,
"eMail": $w('#inpEmail').value,
});
});
});
$w('#dataset1').onBeforeSave(()=>{
$w("#dataset1").add()
.then(()=> {console.log("New item added");})
.catch((err)=> {console.log(err);});
});
$w('#dataset1').onAfterSave(()=>{
//What shall happen when data was saved ?
$w('btnSubmission').disable();
});
});
But it is still not complete !!! Now try first to understand all these, before you make the last step and code the last part of your wished function.
EDIT: If you do not want to CODE to much, you also can try just to use…
Using this example you will have to connect your dataset with all elements.
$w.onReady(function() {console.log("PAGE is READY!");
$w('#dataset1').onReady(()=>{
console.log("DATASET is READY!");
$w('#dataset1').onBeforeSave(()=>{
});
$w('#dataset1').onAfterSave(()=>{
$w('btnSubmission').disable();
});
});
});
But what is the second part? Which function is still missing?
Of course – > you want to disable the Butmit-Button for those, who have already SUBMITTED. And now it gets a little bit more complicated, but this part you will continue next time, after you have understood the first one.
So, using the first lengthy code, that field values for the fields, what am I supposed to put there? I mean, I can’t put one particular value because it’s a lot of users.
Or I’m not supposed to put anything at all. That’s the code for it? (this remark is with regards to the first question asked in this particular comment).
Look, first you have to make clear what exactly you want to do and how it should work. Which are the single steps in your wished function.
The flow …
User logs in → you get the User-ID
User clicks the Submit-Button after filling up the Form
Saving of submissed data starts to database
Button is getting disabled
Also somewhere inside database you generate a FIELD where you save the current state of the button (disabled or enabled for this specific current user, who has done the submission).
But this also means that you have to check the state of this field everytime when a submission has been done, IF-ELSE-QUERY.