One Submission per Member

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.

Please I really need it!

Regarding your issue, first question will be…

  1. Do you use a CUSTOM-CREATED-SUBMIT-FORM ?
  2. Do you use a Wix-Out of the box offered one?

This is important to know.

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…

$w('mySubmissionButtonIdHere').onClick(()=>{
	$w('mySubmissionButtonIdHere').disable();
});

But if you don’t use CODE and you are not a coder, this little info will not be enough to help you.

Generating your wished function without code, is on my opinion impossible.

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.

Thanks again.

And yes, I use a custom form. That is, a collection of user inputs put together

Ok, let’s say you are using the following elements…

  1. you have a DATABASE
  2. you use a dataset (for sure you use a dataset)
  3. you use a CUSTOM-FORM
  4. on your form you will have some INPUT-FIELDS
  5. 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…

  1. First-Name → DB-Field-ID inside your DATABASE = “firstName”
  2. Last-Name → DB-Field-ID inside your DATABASE = “lastName”
  3. e-Mail

of the current user, who is using your form.
You will have then first to set the right fields and field-values…

$w("#dataset1").setFieldValues({
   "firstName":  "xxxxx",  
   "lastName":   "xxxxx",
   "eMail":      "xxxxx"    
});

Here you defined the 3 wished DB-Fields you want to save to.

$w("#dataset1").setFieldValues({
   "firstName":  $w('#inpFirstName').value,  
   "lastName":   $w('#inpLastName').value,
   "eMail":      $w('#inpEmail').value,    
});

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.

Edit: Some further infos here (similar post)…

Thanks.

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.

$w("#dataset1").setFieldValues({
	"firstName": 	$w('#inpFirstName').value,
	"lastName": 	$w('#inpLastName').value,
	"eMail": 	$w('#inpEmail').value,});
});

This one above. The input value for each field should be what, so it can cover every members value?

Plus,
The values for that “title”: “New Title” and “name : New Name”

What in my database ought to go in there?

"title":	"New Title",//<---REPLACE HERE WITH YOUR OWN DATA (FIELD / VALUE)
"name":	"New Name"//<---REPLACE HERE WITH YOUR OWN DATA (FIELD / VALUE)

Then, after writing the very first code you said I should put first, how would I know if it works?

I apologize if the questions feel dumb, but please just help me out. The members are going to need it soon.

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 …

  1. User logs in → you get the User-ID
  2. User clicks the Submit-Button after filling up the Form
  3. Saving of submissed data starts to database
  4. Button is getting disabled
  5. 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).
  6. But this also means that you have to check the state of this field everytime when a submission has been done, IF-ELSE-QUERY.

if() {} else {}