Page 1 of 1

How do I use the username created by the user after signing up to assign it to a label on the next page?

Posted: Sun Jun 01, 2014 7:22 pm
by Stefan Zier

For example, Bob chooses his username to be "bobby." Now on the following page is Bob's profile page. I've added a Label to the page and would like assign Bob's username "bobby" to it. I'd like that Label to change corresponding to each different username in the database. Thank you!!!


How do I use the username created by the user after signing up to assign it to a label on the next page?

Posted: Sun Jun 01, 2014 11:21 pm
by Yurii Orishchuk

Hi Stefan.

You have two ways to do it:

1 Get user name from username input (when sign up service is invoked) and store it in the LSV. See code below:

precode

//Where "userNameInput" - name of the userName input compnent.
var userName = Apperyio("userNameInput");

//Store userName into LSV with name "currentUserName". For futher use.
localStorage.setItem("currentUserName", userName);

/code/pre

2 Use signUp service response. Where return field called "username".
See details here: http://devcenter.appery.io/documentat...

You can store this answer field in to LSV. See details on this screen shot: http://prntscr.com/3ot5zi/direct

When you need to restore this "userName" value onto the other page use following code:

precode

//get value from "currentUserName" LSV.
var storedUserName = localStorage.getItem("currentUserName");

//Where "label_userName" - name of the label component on this page.
Apperyio("label_userName").text(storedUserName);

/code/pre

That's all.

Regards.


How do I use the username created by the user after signing up to assign it to a label on the next page?

Posted: Sun Jun 01, 2014 11:34 pm
by Stefan Zier

Thank you so much for the info! I am a little confused as to how I can implement this. I have a "signup" page and an "account" page as well as a database set up to handle the usernames and passwords.

Where exactly do I add the JS and how do I link that up to the label on my account page?

I am very new with Appery and would appreciate any help you can offer.

Thank you so much!

  • Stefan

How do I use the username created by the user after signing up to assign it to a label on the next page?

Posted: Mon Jun 02, 2014 3:25 am
by Yurii Orishchuk

Stefan,

Please follow these steps:

1 Open page where you have signup form.

2 Open "data" tab on this page. http://prntscr.com/3ouuie/direct

3 Open "events" bottom panel. http://prntscr.com/3ouutv/direct

4 Select in components your signup datasource and add "success" event handler with type "JS" and populate with following JS code: http://prntscr.com/3ouwpf/direct

precode

//Get userName from serviceResponse.
var userName = data.username;

//Save userName into "label_userName" LSV.
localStorage.setItem("label_userName", userName);

/code/pre

5 Then open page where you need to display "userName".

6 Add "JS" event handler to the "page show" event. And fill it with following code: http://prntscr.com/3ouxj1/direct

precode

//get value from "currentUserName" LSV.
var storedUserName = localStorage.getItem("label_userName");

//Where "label_userName" - name of the label component on this page.
Apperyio("label_userName").text(storedUserName);

/code/pre

That's all.

Regards.


How do I use the username created by the user after signing up to assign it to a label on the next page?

Posted: Mon Jun 02, 2014 3:53 am
by Stefan Zier

Hi this was a great answer and I got it to work but I have one big problem. Say Bob logs out of his account and Tim logs in with his account previously created. The label still says "bobby" not "timmy." Since the name is stored as a LSV this does not work when other users log in. So how can this be fixed?

Could you please tell me in the same way you instructed me in your last response. Your steps were very easy to follow and understand.

Thank you so much! I truly appreciate it!


How do I use the username created by the user after signing up to assign it to a label on the next page?

Posted: Mon Jun 02, 2014 4:59 am
by Yurii Orishchuk

Stefan,

That's not a problem.

  1. You have "login" page. Open thie page.

    2 Add "success" event handler on "login" service. And populate it with following code:

    precode

    //Get userName from "userName" input. You should replace "login_userName" with your user_name input component
    var userName = Apperyio("login_userName").val();

    //Save userName into "label_userName" LSV.
    localStorage.setItem("label_userName", userName);

    /code/pre

    Regards.


How do I use the username created by the user after signing up to assign it to a label on the next page?

Posted: Mon Jun 02, 2014 5:19 am
by Stefan Zier

Thank you SO MUCH! This solved the issue I was having. Thanks for all of the instructions!