I have created a page under 'Member Pages ’ that takes other member information that cant be taken under profile page. But I want them to fill those details just once. If they try to write it again a new entry is created in the database, which is something I don’t want. Is there a way I can prevent this?
Do you want to let them update the info (if they fill it again) or you want to hide the form completely if they have already submitted it?
I have a same problem. I want to hide it
Create a ‘Members’ database.
The _id their will be the userId.
Add a ‘hasFilledForm’ field key (Boolean).
Then on the web page make the form and the submit button collapsed on load (via the property panel).
(I’d guess you’re submitting the data via dataset).
Add this code:
import wixData from 'wix-data';
import wixUsers from 'wix-users';
let userId = wixUsers.currentUser.id;
$w.onReady(() => {
wixData.query('Members')
.eq("_id", userId)
.eq('hasFilledForm', true)
.find()
.then(r => {
if(!r.items.length > 0) {
$w('#form').expand();
$w('#submitButton').expand();
}
})
$w('#dataset1').onReady(() => {
$w('#dataset1').onAfterSave( () => {
$w('#form').collapse();
$w('#submitButton').collapse();
wixData.insert('Members', {_id: userId, hasFilledForm: true});
});
})
})
@jonatandor35 Where can i add this code? I added “members” database. I must add text field “id” and Boolean field “hasFilledForm”? Thanks for answer Anyways what type of database it should be? I mean “permissions”
@jmazur2004 you should add it to the page code panel.
The collections should be so the authorized member would be able to read and write (I always choose customize collection so I’ll be able to fit the permissions).
@jonatandor35 In line 21 (last line) i’m getting “unexpected token }”, but when i delete it, I still get “unexpected token” (without and “}” or “)”)
@jmazur2004 see the fix in red in the code above.
@jonatandor35 I’m telling about a dot.
@jmazur2004 are you using the fixed code?
@jonatandor35 What do you mean by fixed code? I deleted all code, then copied yours, then i changed names for " #button1 " for exmple and i’m getting this parsing errors. And I’m getting “unexpected token }”, but when i delete it, I still get “unexpected token”. It’s kinda weird. I’m also not good at wix programming, i only know basics of javascript.
@jmazur2004 A few minutes ago I added a missing parentheses to the code above. Be sure to copy & paste the new code.
@jonatandor35 Oh, sorry, I didn’t notice that. Code isn’t have any errors anymore. But i tried if it is working and nothing chagned in my live database ;(
(I added dataset to the page)
@jmazur2004 I added another line to the code above (sorry for that, I wrote it too fast earlier).
- make sure you set the collection permissions right.
- are you submitting the form to dataset1 ?
@jonatandor35 I added this line to my code.
Everybody can read, create, update and delete things from “Members” database.
The text of input is going to my “#dataset1” which is connected to other database. I have also “#dataset3” which is connected to “Members database”. I just want to make affilate program, so everybody can type code only one time. But still nothing happends. " submit button collapsed on load " I don’t know what does it mean. I only made form with wix tutorial of custom forms. And this part is working.
https://jmazur2004.wixsite.com/csgoskins/partnership
@jmazur2004 click the form, open the property panel, check the collapsed on load checkbox. Do the same to the submit button.