Hello
i would need help i created a member area and in another page i created a form i would like my client to fill the form without rewriting his information, i tried refence field but i don`t do not get there since I'm a novice
please help me
here is my member profile code
import wixUsers from 'wix-users';
import wixData from 'wix-data';
import wixLocation from 'wix-location';
$w.onReady( () => {
if(wixUsers.currentUser.loggedIn) {
$w("#button4").label = "Déconnexion";
$w("#button5").show();
}
else {
$w("#button4").label = "S'identifier";
$w("#button5").hide();
}
} );
export function button4_onclick() {
// user is logged in
if(wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then( () => {
// update buttons accordingly
$w("#button4").label = "S'identifier";
$w("#button5").hide();
} );
}
// user is logged out
else {
let userId;
let userEmail;
// prompt the user to log in
wixUsers.promptLogin( {"mode": "login"} )
.then( (user) => {
userId = user.id;
return user.getEmail();
} )
.then( (email) => {
// check if there is an item for the user in the collection
userEmail = email;
return wixData.query("MemberProfile")
.eq("_id", userId)
.find();
} )
.then( (results) => {
// if an item for the user is not found
if (results.items.length === 0) {
// create an item
const toInsert = {
"_id": userId,
"email": userEmail
};
// add the item to the collection
wixData.insert("MemberProfile", toInsert)
.catch( (err) => {
console.log(err);
} );
}
// update buttons accordingly
$w("#button4").label = "Déconnexion";
$w("#button5").show();
} )
.catch( (err) => {
console.log(err);
} );
}
}
export function button5_onclick() {
wixLocation.to(`/MemberProfile/Update/${wixUsers.currentUser.id}`);
}
hello massa
thank you for your answer yes I did not synchronize I will do it as soon as I'm at home thank you 1000 times
Hello Omar
I checked you website and the first code i provided you with is working and redirecting to the right pages.
Try it out one more time, here's the code :
export function button1_onclick_1(event, $w) { //on button click it stores the user input in the variable "value" let value = $w('#input1').value; //after value stored it should look for it in the database wixData.query("villesdisponibles") .eq("departement", value) //search the field "department" for this value .find() .then((result)=>{ //result has all the items equal to "value" console.log(result) if (!(result.length)){ // value not found which means it is not valid wixLocation.to("/member-profile") } else{ wixLocation.to("/blank-1") } }) }
however you need to syn you data to make sure you have the right data to compare with in the live site.
first thing you need to do is go your dashboard --> Database --> check all your data items (delete wrong data ).
then after you make sure of your live data, go to you website's databases and sync you data to get all the items in the sandbox copied to your live data.
this should surely work :)
good luck!
Massa
Hello Massa
I hope I do not bother you so you could see?
hi here is my site but I am still under construction
https://omarbiddiche.wixsite.com/monsite
make sure that the input type matches the data field type
can you please provide me with your website url? it would make it easier for me to help :)
hello massa
yes here it is actually every time I click on the validation button it sends me each time on the member page.
I add let input = $ w ('# input1'). value;
let value = input.tostring (); I do not see anything that passes me to no page I screen you all to see, but I think I did as you finally told me I hope
I'm sorry but i didn't quite understand what the problem is..
is it always redirecting to the member-profile page?
-i suggest you check your database field's type ( departement ).
-try using to tostring():
let input = $w('#input1').value; let value = input.tostring();
Massa
hi massa
Here is my code I have a small problem is that as soon as I valid can import the right or the wrong answer he sent me to profile a idde?
import wixData from "wix-data"; import wixLocation from "wix-location";
export function button1_click_1(event, $w) { //on button click it stores the user input in the variable "value" let value = $w('#input1').value; //after value stored it should look for it in the database wixData.query("villesdisponibles") .eq("departement", value) //search the field "department" for this value .find() .then((result)=>{ //result has all the items equal to "value" if (!(result.length)){ // value not found which means it is not valid wixLocation.to("/member-profile") } else{ wixLocation.to("/blank-1") } }) }
Hello
i'm glad it's working well !
if you want to redirect the user to a different page use wixLocation.to() :
else{ wixLocation.to(/"Your-Page-Title") }
Massa
Hello
the code is perfect because I'm new in the code I wanted to ask you the code to put in
else{
}
})
to point to another page if the value is valid
ps: sorry I would have pecked you to the end
hello massa
I saw your message this morning but I could not answer because I was at work all day, I had only one desire to answer you and tried it, code;). I make you a return as soon as possible thanks again
one more thing...
connecting the input field to the database field, and connecting the button to submit to database, that will add all the values the users enter to the database on button click as well. so i suggest you disconnect both the input and the button.
Massa
Hello there !
so the problem here is in the place you have the query in and how it's used.
what we want is when the user clicks the button we take the input value and look for it, so the query should be inside the on click event.
what we will be looking for is the value existence in "department" field, if it doesn't exist then send the user to member-profile page. here how it should look like:
import wixData from "wix-data"; import wixLocation from "wix-location"; export function button1_click(event, $w) { //on button click it stores the user input in the variable "value" let value = $w('#input1').value; //after value stored it should look for it in the database wixData.query("villesdisponibles") .eq("department", value) //search the field "department" for this value .find() .then((result)=>{ //result has all the items equal to "value" if (!(result.length)){ // value not found which means it is not valid wixLocation.to("/member-profile") } else{ // if you want any thing to happen if the value is found (valid) you can add it inside the else } }) }
Massa
re massa
I put this code (sorry I'm new to code)
I put in capture stages, in your opinion?
re
massa thank you thank you for everything I do not bother you anymore unless I block again;) finally if you do not mind
good day and happy to be on you
I suggest the following:
add a database that includes all the available values you have
add user input and a button
when the user clicks on the button it checks if the value entered exists in the database (valid).
If it doesn't exist you can redirect the user to a different page using wixLocation.to().
check the following :
to query the database to search the input: https://www.wix.com/code/reference/wix-data.WixDataQuery.html#eq
to redirect to a different page: https://www.wix.com/code/reference/wix-location.html#to
to add an event on button click:
however, to make sure the user enters the value in the format you want you can add a regex (pattern validation) to the user input:
I hope that solves the case :)
Massa
re massa
ok well understood, in fact I'm poorly expressed I pence
the client enters values, example I authorize that the values (95100,92600,93677, ect.) in this case it is directed towards the member space
in case it does not fit the 5 good figure it is redirected to an excuse page because we do not issue this area
basically it's just to say if are departement is available or not
example:
http://www.pressingadomi.fr/tarifs-et-prestations.htm
ps: sorry to keep you with my questions and thank you in advance for the attention is the reactivity of your message
hello
I'm glad it worked!
if you want google Autocomplete for addresses you can follow this link : https://developers.google.com/maps/documentation/javascript/places-autocomplete
however, landing the user on a page which invites him to leave his coordinates so that it is recontact is not possible.
Massa
hello massa
Already a big thank you for your answer it was instructive, and it works I'm all happy =)
tell me I also wanted filtered like this site, https://www.zipjet.fr/
then the customer enters are address and if it is deliverable then it lands on its page of connection in the opposite case it lands on a page which invites him to leave his coordinates so that it is recontact you can help me to make this ??
Hello
As i understood you want to have some fields in the form filled by user's info. There's some fields you can fill (like email) by getting the user's info and setting the text of the input field to it :
let user = wixUsers.currentUser; user.getEmail().then((email) => { $w('#emailInput').value = email; })
here u can find more about your current users: https://www.wix.com/code/reference/wix-users.html#currentUser
Massa