Hello everybody.
I’m trying to build a custom form with custom “user input” fields and I’ve connected every field to a database collection. Then I’ve used sendgrid API to deliver the form submissions to a specific email. Everything work perfectly, but I need more: this form is a sort of order request for a food distribution company that have about to ten customers, each with his different inputs (or one different/three same/etc). In order to understand WHO has submitted the form I was thinking in these ways, but I can’t figure out which is the most useful and doable:
- Add the user email on sendgrid code to print it on form submission email
- Redirect user after login on his specific form (based on his mail or other fixed parameter)
- Change the content of a dynamic page on specific user id (different forms for different users)
What are the best solutions and how can I apply them?
Thank you very much!
Hi Andrea,
Great that you already have a working solution. These are my thoughts on how you could further improve it:
-
The easiest and fastest way would be to attach the user email to the submitted form, but is is good enough from the business perspective? In that case every user would get all the fields and would need to know which fields he/she needs to fill.
-
The next approach in terms of difficulty would be to create a separate form for every user and redirect it based on its email. This solution does not scale, but if the company has a constant number of customers and the form is not going to change, this could be a cheap win. IMO it would be easier to create regular pages instead of dynamic ones.
-
Having a single form and changing content is the most challenging approach. You would need to store the applicable form fields for every user and then show/hide them when the page loads. Also, hiding some form fields might leave an empty gap in the page.
-
You could also go with the first approach and in case you need to improve the user experience, you could apply the 3rd mechanism on top of it, but instead of showing/hiding form inputs you could disable them or mark them as not needed. That way you would avoid the layouting problem.
Good luck!
Marius
Hello Marius and thank you for your precious contribution.
Number 2: “if the company has a constant number of customers and the form is not going to change, this could be a cheap win”. This is exactly the right example, so this can be the best solution!
My request, however, was oriented on how can I accomplish this goal. Can you (or other users) explain to me how to do it step by step?
That would be really appreciated.
Thank you and have a nice evening.
@ Andrea Peruzzetto
you can get the email address of the member that is currently logged in when they are filling out your form with the below code. Then once you have their email just pass it to your database along with the rest of the info they are submitting to your database.
import wixUsers from ‘wix-users’;
$w.onReady( function () {
// if user is logged in
if (wixUsers.currentUser.loggedIn) {
let user = wixUsers.currentUser;
user.getEmail()
.then((email) => {
let userEmail = email;
console.log(userEmail);
// then just pass the userEmail to your database
})
}
})
Hello Mike!
It’s working but…how can I pass the user email to database?
Thank you very much
@andreasperuz14173
//change this button ID to the correct ID for your button
$w(‘#formSubmitButton’).onClick( function () {
//change this dataset1 ID to the correct ID for your dataset
$w(“#dataset1”).onReady(() => {
// change email to the correct fieldKey for your database
$w(‘#dataset1’).setFieldValue(‘email’, (userEmail));
('#dataset1').save(); //change this dataset ID to the correct ID for your dataset
})
})
@mikemoynihan99 can I redirect after the #accountnavbar log out is clicked - currently opens Wix Log In page but I have a custom log in page so this isn’t right
@jbroadstock
try this:
$w("# accountnavbar ").link = “http://www.google.com”; //change to what ever website you want to redirect to
@mikemoynihan99 Hi Mike,
Thanks for the reply. Here’s the response on the code.
‘link’ does not exist on ‘#accountNavBar1’
@jbroadstock
Ok then try this:
import wixLocation from ‘wix-location’;
$w.onReady( function () {
$w('#accountNavBar1').onClick( function () {
wixLocation.to('https://www.google.com');
})
})
@mikemoynihan99 OnClick does not exist on accountNavBar1 
@jbroadstock have you got a picture of this NavBar ?
@jbroadstock
Note sure why you are using that NavBar. If you have a custom login page just run the below code on it. You can replace that NavBar with some text i.e. “Login/Out”, then just create a link on the text to your custom login/out page.
import wixUsers from ‘wix-users’;
import wixLocation from ‘wix-location’;
$w.onReady( function () {
// if user is logged in
if (wixUsers.currentUser.loggedIn) {
$w("#LoginButton").label = "Logout";
})
} **else** {
$w("#LoginButton").label = "Login";
}
$w('#LoginButton').onClick( function () {
if (wixUsers.currentUser.loggedIn) {
// logout the user
wixUsers.logout()
console.log("successful logout");
} **else** {
// login the user
let email = $w(‘#LoginEmailInput’).value;
let password = $w(‘#LoginPasswordInput’).value;
wixUsers.login(email, password)
.then(() => {
wixLocation.to('https://www.google.com');
})
. catch ((error) => {
console.log("failed login");
})
}
})
}
)
@mikemoynihan99 Thanks Mike, I used to have that code on my page however I’ve changed around my layout - I have this navbar for the dropdown to members profiles in the header - the problem is the log out button you can see here redirects to the wix log in lightbox and not my custom lightbox. When a user isn’t signed in this navbar says login and redirects to my login lightbox
Would you suggest shifting all this round?
@mikemoynihan99 Ok thanks so much for your help!
Thank you all for your support. I’ll waiting for any solutions on point Number 2!
@mikemoynihan99 Hello.
So, the user email is now displayed in the database collection, but my real need is to visualize it on a user input or similar, because i want to add it on the text of email processed by sendgrid integration.
Hello everybody.
So, the user email is now displayed in the database collection, but my real need is to visualize it on a user input or similar, because i want to add it on the text of email processed by sendgrid integration.