1. We suggest you do NOT update to Joomla 3.8.10 until we can resolve an issue it causes with caching in Fabrik. If you do install it, you'll need to disable Joomla's "System Cache" in the global System settings.
  2. Apologies for the recent server outage, a planned migration by our host provider to a new location turned into a bit of a nightmare.

Get Current User's profile values for Fabrik form?

Discussion in 'Community' started by fabrikg09, Sep 14, 2012.

  1. fabrikg09

    fabrikg09 Member

    Level: Community
    Is there a way of referring to the ALL of the variables containing the values of the current user's profile into a Fabrik element of the field type?

    I wrote a custom user profile that adds entries for Company and Full Name, and I want to pull these values onto a Fabrik form. Sort of performing the same function as an autofill. (The autofill feature seems difficult/impossible to grasp, at least to me...)

    I've been able to get SOME of the values by putting, for instance, this into the Options/Eval box:

    $user =& JFactory::getUser();
    $email = $user->get('email');
    return $email;
    //that works fine//

    $user =& JFactory::getUser();
    $username = $user->get('username');
    return $username;
    //also works fine//

    But if I try this, which refers to one of the standard profile items, phone:

    $user =& JFactory::getUser();
    $phone = $user->get('phone');
    return $phone;

    It returns nothing. Are not all of the entries in the user's profile contained in the session values? If so, how does one call them?
  2. troester

    troester Well-Known Member Staff Member

    Level: Standard
    "Phone" is no Joomla user profile item.

    For the other ones: it depends what you want to do:
    -pull existing values (the user can modify, modification only in your own profile list): autofill or the way you mentioned
    -Keep your profile entries synchronized with the Joomla user entries: add form plugin jUser
    - display Joomla profile values: user element or dbjoin element to #_users
  3. fabrikg09

    fabrikg09 Member

    Level: Community
    This is apparently the problem - what exactly are the user profile variables that can be accessed?

    I think I will have to pull the info by using PHP and going directly to the table in question. I just want to autofill Name and Company (two of my custom profile fields) on to my Fabrik form, so that:

    1.)The user doesn't have to do this
    2.) When the email is sent, it contains Name and Company, which for a large number of users, is more convenient than seeing the username or id.
  4. mrvan

    mrvan New Member

    Level: Community
    Hi fabrikg09

    Have you managed to find a solution to add Company into the user profile? I need to create a pre-filter for a list which can use the fabrik user plugin to filter the data by company.

  5. fabrikg09

    fabrikg09 Member

    Level: Community
    Yes - I originally did that by creating a custom user profile, adding the fields that I needed. Once the new fields have been added, it is easy to bring them into a Fabrik form element. My custom profile is called "profile10" here:

    $db =& JFactory::getDBO();
    $query = "SELECT SUBSTR(`profile_value`,2,LENGTH(`profile_value`)-2) AS `profile_value` FROM `mysite_user_profiles` WHERE `user_id` = '{$my->id}' AND `profile_key` = 'profile10.company'";
    $cname = $db->loadResult();
    return $cname;

    I couldn't have figured this out without the excellent support I received from the Fabrik developers here! HTH

    NB: There are a lot of good references online to explain the details of creating a custom user profile. Just Google the problem.
    magj likes this.
  6. magj

    magj Member

    Level: Community
    Sorry for bumping this old thread up but it may help me or someone .

    I successfully mad a profile plugin and used this code to show custom profile information but there is problem with unicode characters, they are saved and displayed as json encoded : i.e.: \u0435\u0442\u0430\u0436

    $db =& JFactory::getDBO();
    $query = "SELECT SUBSTR(`profile_value`,2,LENGTH(`profile_value`)-2) AS `profile_value` FROM `mysite_user_profiles` WHERE `user_id` = '{$my->id}' AND `profile_key` = 'profile10.company'";
    $cname = $db->loadResult();
    return $cname;​

    I tried something like:
    $cname1 = json_decode($cname)
    return $cname;​
    it shows a blank result
    How may I decode them?

    Any help would be greatly appreciated
  7. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Professional
    That's not actually JSON encoded, that's unicode. Although one convenient way of decoding it is to run it through json_decode. However, you'd have to wrap double quotes round it, to make it a valid JSON string, like ...

    Code (Text):
    $cname = json_decode('"' . $cname . '"');
    Although I suspect the root of the problem may be your table's character set and collation. Setting it to something like charset utf8 and collation of utf8_general_ci might cure the problem.

    -- hugh
    magj likes this.
  8. magj

    magj Member

    Level: Community
    THANK you very much,

    Yes, the first thing I did, was to change and correct the collation to : utf8_unicode_ci and your code made it to work.

    I really appreciate your great job

Share This Page