I’m confused

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

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!!!
1 person has
this question
+1
This topic is no longer open for comments or replies.
  • 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:



    //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);



    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:



    //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);



    That's all.

    Regards.
    • 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
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated happy, confident, thankful, excited kidding, amused, unsure, silly indifferent, undecided, unconcerned

  • 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



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

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



    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



    //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);



    That's all.

    Regards.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated happy, confident, thankful, excited kidding, amused, unsure, silly indifferent, undecided, unconcerned

  • 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!
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated happy, confident, thankful, excited kidding, amused, unsure, silly indifferent, undecided, unconcerned

  • 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:



    //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);



    Regards.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated happy, confident, thankful, excited kidding, amused, unsure, silly indifferent, undecided, unconcerned

  • Thank you SO MUCH! This solved the issue I was having. Thanks for all of the instructions!
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated happy, confident, thankful, excited kidding, amused, unsure, silly indifferent, undecided, unconcerned