User element to grab logged in user?

Discussion in 'Community' started by Tessa, Nov 10, 2011.

  1. Tessa Member

    Level: Professional
    I know the php code to grab the logged in username but have no clue what page the code is coming from. I think i've looked everywhere and it's really hard to figure out where it is stored. I'll look again.

    Does Fabrik have an element where I can detect a logged in user so I have a column that says "Uploaded By: ".

    A drop down list is dangerous for choosing a user because employees can lie about who uploaded the file and that could be dangerous.

    And having hundreds of users would make it difficult to find your username on the drop down list too...

  2. troester Well-Known Member

    Level: Standard
    Add a "user" element; you can set it to hidden, update on edit, so the last user who modified the record will be recorded.
  3. Tessa Member

    Level: Professional
    Thank you, that worked!
  4. ritesh123 Member

    Level: Community
    I am not getting correct data for "last Updated by".
    it is showing same as "originated by" with user element.

    BTW is kept as 'Update on edit"

    any idea is there any bug fix on that?
  5. troester Well-Known Member

    Level: Standard
    Should do. What is your fabrik version?
  6. ritesh123 Member

    Level: Community

    Do we need to do some parameter settings?
  7. cheesegrits Support Gopher

    Level: Community
    Is the "updated by" either hidden, and/or have Access set above the level of the regular users?

    The way the "update on edit" feature currently works is, if the element is visible and the logged on user has edit access on the element, then we won't automagically set it to the logged on user, we'll use whatever is selected in the dropdown.

    -- hugh
  8. cheesegrits Support Gopher

    Level: Community
    Actually the logic is, if 'update on edit' is set, and it is NOT editable OR if it is hidden, we will automatically update with the logged on user.

    Rob and I have kind of been arguing about that logic for a while now.

    I'm probably going to modify the "update on edit" choices, so they become:

    If not editable or hidden

    .. so you can set it to "always" and avoid the current confusion.

    -- hugh
  9. ritesh123 Member

    Level: Community
    It is visible to user as "Read Only" in the form and user cannot edit it.

    The Updated by should change when some user edits any field.

    For Example "User A" create the Form

    Form has two fields : Created By and Updated By ( both Read Only in Form)
    I get data like this

    Created By: User A
    Updated By: User A

    Then "USER B" logs in and edits the record.
    My expectation is we should get

    Created By: User A
    Updated By: User B

    But i am getting for both as USER A
  10. jfquestiaux Well-Known Member

    Level: Professional
    I think that when a field is set to "Read Only", it does not get updated once it is set to a value.
    I don't know your setting, but if you want to display the information, you should show it in the table view but hide the element in the form (and DON'T set it to read only or to higher access right than the user has).
  11. Tessa Member

    Level: Professional
    I am staying tuned for more information on this. My forms will be requiring a "Created by" And "Updated By" for every page.
  12. troester Well-Known Member

    Level: Standard
    You can add two user element, one with update on edit=no (->created by), one with yes.
  13. Tessa Member

    Level: Professional
    Wow I really appreciate your response.

    It means a lot. :D
  14. ritesh123 Member

    Level: Community
    Just for the benefit of other i have created a Last Updated By Plugin by which you can determine the last updated by for a particular form

    Just create a column in your table as "last updated by"
    Add this below code in php plugin script and use this as Submission plugin of form"After Submission"

    Here is the code

    defined('_JEXEC') or die();
    $user =& JFactory::getUser();
    $rowid = JRequest::getVar('rowid');
    $db =&JFactory::getDBO();

    # Update only one below parameter for "Last Update By Feature"
    $fortable="table name";
    mysql_query("UPDATE $fortable SET $fortable.columnname=$updateid WHERE $$rowid");


    Thats it

    For "Created by" functionality you can use Date element
  15. Tessa Member

    Level: Professional
    What's the point of using this method when you can just "hide" it and it automatically pulls the logged in user name?

    I don't understand why this should be considered an alternative method when the other way is easier.

    Just wondering ;-)

  16. Tessa Member

    Level: Professional

    Okay so my last response did not make sense.

    But I understand what you mean now. I am at the point where I am using the "Created By" and "Last Updated By" user elements.

    Can someone explain how to create this?

    When I fill out the form, it says "Created by Tessa" and "Last Updated By Tessa" when I need the "Last Updated By" to be blank, until someone edits it.

    I have 2 user elements, both set to hidden, 2nd user element is set to "Update on Edit".

    Thank you :)
  17. deepakdhingra Member

    Level: Community
    Forgive me for butting in here ---But how did you get the logged in user's name? I am using Fabrik 2.1.1 and what I get is the user ID, not the user name? How do I get the username with the user element?

    And even though Ritesh has explained the PHP thing, he did not explain this "For "Created by" functionality you can use Date element"

    Would be nice if anyone could tell me.


  18. troester Well-Known Member

    Level: Standard
    In the user element select from the "User Data" dropdown what you want to see (in the database it's always storing the userID).

    "Update on edit"=no: userID of the logged in user is stored only when a new record is created (and not modified when editing an existing record)
    "Update on edit"=yes: userID is modified when editing an existing record
    1 person likes this.
  19. deepakdhingra Member

    Level: Community
    Thank you, Troester. That was so silly of me not to have noticed the User Data dropdown. I assumed it pulls in only the ID. Thanks again. Deepak

Share This Page