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.

Value of the user's id - form plugin

Discussion in 'Professional Support' started by erricogiu, Jul 12, 2018.

  1. erricogiu

    erricogiu New Member

    Level: Professional
    Hello,
    I am working with a form plugin to send an email to a user.
    One of the elements of the form is the user's id. From this id I can get the email address to send the message. I do this without problems. I use the function to access the database from the PHP code of the plugin with "JFactory :: getDbo ()". All ok.

    The problem that seems simple, but I can not find a way to do it is to know the value of the user's id of the form!

    Use Fabrik 3.8.1, Joomla Joomla! 3.8.8, PHP 7.0.30,

    I try to follow the instructions of:
    http://fabrikar.com/forums/index.php?wiki/php-form-plugin/#accessing-form-data

    but I do not get results

    I attach the data of the elements so they can help me in a concrete way.
     

    Attached Files:

  2. troester

    troester Well-Known Member Staff Member

    Level: Standard
    Can you give some more informations?
    Your screenshot says you are using the form email plugin, WIKI "accessing-form-data" is for form php plugin.

    What are your exact settings (PHP/HTML template? Article template? Message text directly?...)

    Usually you should be able to get the form data with placeholders, something like
    $product_id ='{transferred_products___product_id}';
     
  3. erricogiu

    erricogiu New Member

    Level: Professional
    Actually I try to use PHP code in "Email to (eval)" of the "email" plugin

    But it does not work either if I try to use it in form php plugin.

    The instruction that I try to use is
    $ user_from = '{transferred_products___user_from}';
    print "user_from:" $ product_id; exit;

    and the result is the 3rd image that I attached.

    Images 1 and 2 are the data that you ask me

    Thank you!!
     

    Attached Files:

  4. troester

    troester Well-Known Member Staff Member

    Level: Standard
    You are setting $user_from and printing the non-existing $product_id, what do you want to achieve?
    "Email to (eval)" is for evaluating (and returning) an email address.

    Your user element will store the J! userid as raw value (and contain whatever you've selected as value: name, username, email).
    Asuming your user element is not showing the email then you must fetch the email from the database
    http://fabrikar.com/forums/index.php?wiki/php-common-tasks/#select
    e.g.
    $user_from = '{transferred_products___user_from_raw}'; //get the J!userid
    $myDb= JFactory::getDbo();
    $myQuery=$myDb->getQuery(true);

    $myQuery
    ->select('email')
    ->from('#__users')
    ->where('id = '.$myDb->quote($user_from));

    $myDb->setQuery($myQuery);
    $email=$myDb->loadResult();

    return $email;
     
  5. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Professional
    There's actually an easier way, using JFactory::getUser() ...

    Code (Text):

    return JFactory::getUser((int)'{transferred_products___user_from_raw}')->get('email');
     
    -- hugh
     

Share This Page