1. Fabrik 3.7 is now available. This version contains critical security updates, please update as soon as possible. Please remember to backup your site before updating, we also recommend testing your updates on development sites if possible.
  2. We had to restore the site around midday (CST) on Wed 7/26 from a backup approximately 8 hours old. So a few posts in the forums were lost. You may want to check to see if you need to re-post anything.

Discover User ID after form process

Discussion in 'Standard Support' started by ourblok, Sep 12, 2017.

  1. ourblok

    ourblok Member

    Level: Standard
    I'm going to use the Juser form plugin so that my team leaders can add members to the site and their group. I'm using the PHP form plugin to insert a row into a table (onAfterProcess) that has: groupid, memberid, approved and permissions - (This is for JomSocial _community_groups_members table).

    I assume that when the form is submitted, it simply autoincrements the userid the for the Joomla _users Table. I need to be able to capture the new user's ID and add it to the insert values as memberid for the _community_groups_members table.

    How, I ask you... HOW?!?!?

    Is there a way I can have an element capture the new userid on submit?

    You're help is valued and appreciated.
  2. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    When setting up the juser plugin, you have to specify the element on the form that holds the newly assigned user ID. That element should then contain that ID when your onAfterProcess code runs, so in (say) $formModel->formData['userid'] or $formModel->formDataWithTableName['yourtable___userid'].

    (NOTE that onAfterProcess, entries in $formModel->formData[] have had the tablename___ prefix removed, but there's a copy of the data that still has them, formDataWithTableName)

    -- hugh
    ourblok likes this.
  3. ourblok

    ourblok Member

    Level: Standard
    You're solution was so simple I had a hard time accepting it. For other novices like myself, here's exactly what i did.
    • Create a field element called "whatever_you_want". I have Eval set to "No"
    • Using the juser form plugin, be sure that the user id is assigned to "whatever_you_want".
    • Using the php form plugin, for the "Process Script" dropdown, select "End of form submission (onAfterProcess)".
    Here is the code I used:
    Code (Text):
    $newuserid = $formModel->formData['whatever_you_want'];
    return $newuserid;

    Thanks Hugh for the valuable guidance.

Share This Page