• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

Trying to send data to AcyMailier through the Plug- ins PHP Code

hitek6456

New Member
I'm able to get the data from the $myEmail and $myProject but having difficulty with $myName. The element that I'm trying to get the data from is a drop down and I wanted the name value, but the raw data keeps coming over. Not sure what I'm doing wrong? The element has the name of a person in the name field and the value has their email. Please help.

$myEmail = '{ministry_projects___assigned_raw}';
$myName = '{ministry_projects___assigned}';
$myProject = '{ministry_projects___project}';

if (!empty($myEmail)) {
if (! include_once JPATH_ADMINISTRATOR . '/components/com_acymailing/helpers/helper.php')
{
throw new RuntimeException("Acymailing not installed");
return false;
}

$myUser = new stdClass();
$myUser->email = $myEmail;
$myUser->name = $myName;
$myUser->project = $myProject;

//If you require a confirmation but don't want the user to have to confirm his subscription via the API, you can set the confirmed field to 1:
//$myUser->confirmed = 1;
$subscriberClass = acymailing_get('class.subscriber');
$subid = $subscriberClass->save($myUser);

$newSubscription = array();
$newList = array();
$newList['status'] = 1;
$newSubscription[4] = $newList; // Replace 2 with the ID of the list.

$subscriberClass->saveSubscription($subid,$newSubscription);
}
 
I'm assuming this is a form submission script. What hook is it running on? Like onBeforeProcess, etc.

The problem with dropdowns (or checkboxes, or radios) is that the data submitted with the form is the "value". The "label" isn't part of the form's posted data. That's not a "Fabrik thing", it's an HTML thing. The labels on dropdowns, checkboxes etc are just displayed text, they aren't part of the <input value="..."> or <option value="...">.

So Fabrik has to pre-process submitted data, and figure out what the "non raw" labels should be. In the case of dropdowns, this means loading the element's params, and matching the submitted value with the settings.

And depending which hook your form plugin is running on, that pre-processing may not have happened yet.

On another note ... from a design point of view, it's MUCH better to use a join element for stuff like that. Rather than have a dropdown with emails and names hard wired into Fabrik's settings. Have a table for 'assigned', with id, name and email. Set up your 'assigned' element as a join with 'id' as the value, and 'name' as the label.

That's just sensible design. That way, if someone's email or name changes, it doesn't matter, you just change it in the table. The data you recorded is just the PK of that row. It also makes stuff like this much easier, as you can then easily get whatever data you need from that, by doing normal database lookups, without needing to rely on Fabrik doing any magic, or understanding how Fabrik stores those value/label tuples. And it means you can present a UI for other people to add / edit those "assigned" values on the front end, in a Fabrik list, rather than having to do it through the element settings. This is relational database normalization 101.

Code:
$myAssignedId = '{ministry_projects___assigned_raw}';
$myAssignedId = is_array($myAssignedId) ? $myAssignedId[0] : $myAssignedId;

if (!empty($myAssignedId)) {
   $myDb = JFactory::getDbo();
   $myQuery = $myDb->getQuery(true);
   $myQuery->select('name, email')->from('assigned')->where('id = ' . $myDb->quote($myAssignedId));
   $myDb->setQuery($myQuery);
   $myAssigned = $myDb->loadObject();

   if (!empty($myAssigned)) {
      $myUser = new stdClass();
      $myUser->email = $myAssigned->email; 
      $myUser->name = $myAssigned->name;
     // etc etc
   }
}

-- hugh
 
Thank you for the info and education. I will try and do it with a database join like you said. After reading you response, I though I would like to pull the data from the joomla users data. What would the process be in doing it that way? So new at this, sorry for the kindergarten questions.

I'm assuming this is a form submission script. What hook is it running on? Like onBeforeProcess, etc.

The problem with dropdowns (or checkboxes, or radios) is that the data submitted with the form is the "value". The "label" isn't part of the form's posted data. That's not a "Fabrik thing", it's an HTML thing. The labels on dropdowns, checkboxes etc are just displayed text, they aren't part of the <input value="..."> or <option value="...">.

So Fabrik has to pre-process submitted data, and figure out what the "non raw" labels should be. In the case of dropdowns, this means loading the element's params, and matching the submitted value with the settings.

And depending which hook your form plugin is running on, that pre-processing may not have happened yet.

On another note ... from a design point of view, it's MUCH better to use a join element for stuff like that. Rather than have a dropdown with emails and names hard wired into Fabrik's settings. Have a table for 'assigned', with id, name and email. Set up your 'assigned' element as a join with 'id' as the value, and 'name' as the label.

That's just sensible design. That way, if someone's email or name changes, it doesn't matter, you just change it in the table. The data you recorded is just the PK of that row. It also makes stuff like this much easier, as you can then easily get whatever data you need from that, by doing normal database lookups, without needing to rely on Fabrik doing any magic, or understanding how Fabrik stores those value/label tuples. And it means you can present a UI for other people to add / edit those "assigned" values on the front end, in a Fabrik list, rather than having to do it through the element settings. This is relational database normalization 101.

Code:
$myAssignedId = '{ministry_projects___assigned_raw}';
$myAssignedId = is_array($myAssignedId) ? $myAssignedId[0] : $myAssignedId;

if (!empty($myAssignedId)) {
   $myDb = JFactory::getDbo();
   $myQuery = $myDb->getQuery(true);
   $myQuery->select('name, email')->from('assigned')->where('id = ' . $myDb->quote($myAssignedId));
   $myDb->setQuery($myQuery);
   $myAssigned = $myDb->loadObject();

   if (!empty($myAssigned)) {
      $myUser = new stdClass();
      $myUser->email = $myAssigned->email;
      $myUser->name = $myAssigned->name;
     // etc etc
   }
}

-- hugh
 
sorry for the kindergarten questions.

No need to apologize for asking questions, that's why you have a subscription. And as my mother always says, the only stupid questions are ones you don't ask.

After reading you response, I though I would like to pull the data from the joomla users data. What would the process be in doing it that way?

That kind of depends on how you want to structure your "assigned" users. If they are just J! users, and the names and emails you want to use are just their normal J! account ones, and you don't have any other concept of "users" for your application (like a "staff" table, which has additional info about the users, etc), then it makes sense to just have that 'assigned' element as a join to the main J! #__users table. Although you'd probably want to restrict it to displaying just users in a specific J! group, rather than all users.

To do that, you can add a "WHERE filter" to the join element. You just need to know the numeric ID of the group you want to display, which is the number on the right when you look at your list of groups on the J! backend. The where clause would look like this, for group id (say) 20 ...

Code:
WHERE {thistable}.id IN (SELECT user_id FROM #__users_usergroup_map WHERE group_id = '20')

Leave that as-is, don't change the {thistable}, it has a specific meaning. Make the join to your J! users table, set 'id' as the value, and 'name' (or whatever you want) as the label.

Having it be the userid also makes the code a little easier, as you can use J!'s JUser API instead of rolling your own query ...

Code:
$myAssignedUserId = '{ministry_projects___assigned_raw}';
$myAssignedUserId = is_array($myAssignedUserId) ? $myAssignedUserId[0] : $myAssignedUserId;

if (!empty($myAssignedUserId)) {
   $myAssignedUser = JFactory::getUser($myAssignedUserId);
   $myUser = new stdClass();
   $myUser->email = $myAssignedUser->get('email');
   $myUser->name = $myAssignedUser->get{'name');
    // etc etc
}

you can get->() any field which is part of the J! users table, like ->get('username').

-- hugh
 
Ok, I'm doing something wrong. Can you look at it.

$myAssignedUserId = '{ministry_projects___assigned_raw}';
$myAssignedUserId = is_array($myAssignedUserId) ? $myAssignedUserId[0] : $myAssignedUserId;
$myProject = '{ministry_projects___project}';

if (!empty($myAssignedUserId)) {
$myAssignedUser = JFactory::getUser($myAssignedUserId);
}

$myUser = new stdClass();
$myUser->email = $myAssignedUser->get('email');
$myUser->name = $myAssignedUser->get{'name');
$myUser->project = $myProject;

//If you require a confirmation but don't want the user to have to confirm his subscription via the API, you can set the confirmed field to 1:
//$myUser->confirmed = 1;
$subscriberClass = acymailing_get('class.subscriber');
$subid = $subscriberClass->save($myUser);

$newSubscription = array();
$newList = array();
$newList['status'] = 1;
$newSubscription[4] = $newList; // Replace 2 with the ID of the list.

$subscriberClass->saveSubscription($subid,$newSubscription);
}

No need to apologize for asking questions, that's why you have a subscription. And as my mother always says, the only stupid questions are ones you don't ask.



That kind of depends on how you want to structure your "assigned" users. If they are just J! users, and the names and emails you want to use are just their normal J! account ones, and you don't have any other concept of "users" for your application (like a "staff" table, which has additional info about the users, etc), then it makes sense to just have that 'assigned' element as a join to the main J! #__users table. Although you'd probably want to restrict it to displaying just users in a specific J! group, rather than all users.

To do that, you can add a "WHERE filter" to the join element. You just need to know the numeric ID of the group you want to display, which is the number on the right when you look at your list of groups on the J! backend. The where clause would look like this, for group id (say) 20 ...

Code:
WHERE {thistable}.id IN (SELECT user_id FROM #__users_usergroup_map WHERE group_id = '20')

Leave that as-is, don't change the {thistable}, it has a specific meaning. Make the join to your J! users table, set 'id' as the value, and 'name' (or whatever you want) as the label.

Having it be the userid also makes the code a little easier, as you can use J!'s JUser API instead of rolling your own query ...

Code:
$myAssignedUserId = '{ministry_projects___assigned_raw}';
$myAssignedUserId = is_array($myAssignedUserId) ? $myAssignedUserId[0] : $myAssignedUserId;

if (!empty($myAssignedUserId)) {
   $myAssignedUser = JFactory::getUser($myAssignedUserId);
   $myUser = new stdClass();
   $myUser->email = $myAssignedUser->get('email');
   $myUser->name = $myAssignedUser->get{'name');
    // etc etc
}

you can get->() any field which is part of the J! users table, like ->get('username').

-- hugh
 
You had mismatching braces.

Try using something like notepad++ or some other "intelligent" editor that groks PHP to write your code, so it points out the syntax errors to you.

Code:
$myAssignedUserId = '{ministry_projects___assigned_raw}';
$myAssignedUserId = is_array($myAssignedUserId) ? $myAssignedUserId[0] : $myAssignedUserId;
$myProject = '{ministry_projects___project}';

if (!empty($myAssignedUserId))
{
    $myAssignedUser = JFactory::getUser($myAssignedUserId);

    $myUser          = new stdClass();
    $myUser->email   = $myAssignedUser->get('email');
    $myUser->name    = $myAssignedUser->get('name');
    $myUser->project = $myProject;
   
    $subscriberClass = acymailing_get('class.subscriber');
    $subid           = $subscriberClass->save($myUser);

    $newSubscription    = array();
    $newList            = array();
    $newList['status']  = 1;
    $newSubscription[4] = $newList; // Replace 2 with the ID of the list.

    $subscriberClass->saveSubscription($subid, $newSubscription);
}

-- hugh
 
Ok, will get notepad++. But i'm still getting an error message.

Notice
: Undefined property: stdClass::$ministry_projects___id_raw in /home/sniper6456/public_html/ysk_cvc/plugins/fabrik_element/fileupload/fileupload.php on line 1614

Fatal error: Call to undefined function acymailing_get() in /home/sniper6456/public_html/ysk_cvc/plugins/fabrik_form/php/php.php(453) : eval()'d code on line 14


You had mismatching braces.

Try using something like notepad++ or some other "intelligent" editor that groks PHP to write your code, so it points out the syntax errors to you.

Code:
$myAssignedUserId = '{ministry_projects___assigned_raw}';
$myAssignedUserId = is_array($myAssignedUserId) ? $myAssignedUserId[0] : $myAssignedUserId;
$myProject = '{ministry_projects___project}';

if (!empty($myAssignedUserId))
{
    $myAssignedUser = JFactory::getUser($myAssignedUserId);

    $myUser          = new stdClass();
    $myUser->email   = $myAssignedUser->get('email');
    $myUser->name    = $myAssignedUser->get('name');
    $myUser->project = $myProject;
  
    $subscriberClass = acymailing_get('class.subscriber');
    $subid           = $subscriberClass->save($myUser);

    $newSubscription    = array();
    $newList            = array();
    $newList['status']  = 1;
    $newSubscription[4] = $newList; // Replace 2 with the ID of the list.

    $subscriberClass->saveSubscription($subid, $newSubscription);
}

-- hugh
 
OK, I was able to get it to work with the Joomla User data. I tried it on another database by using using a new the method you indicated. I created a new table to add users and called it sk_add. In that table I added the elements you requested. Then I added the databasejoin field in a table called "soulkeeper". In the addon of the soulkeeper form, I added the below code. Can you tell me what I'm doing wrong?

$myAssignedId = '{soulkeeper___soulkeeper_raw}';
$myAssignedId = is_array($myAssignedId) ? $myAssignedId[0] : $myAssignedId;
$myVisitor = '{soulkeeper___name}';
$myPhone = '{soulkeeper___mobile}';
$myVis_Email ='{soulkeeper___email}';

if (!empty($myAssignedId)) {
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);
$myQuery->select('name, email, phone')->from('add_sk')->where('id = ' . $myDb->quote($myAssignedId));
$myDb->setQuery($myQuery);
$myAssignedId = $myDb->loadObject();

if (! include_once JPATH_ADMINISTRATOR . '/components/com_acymailing/helpers/helper.php')
{
throw new RuntimeException("Acymailing not installed");
return false;
}

$myUser = new stdClass();
$myUser->email = $myAssignedId->get email;
$myUser->name = $myAssignedId->get name;
$myUser->skphone = $myAssignedId->get phone;
$myUser->visitor = $myVisitor;
$myUser->phone = $myPhone;
$myUser->visemail = $myVis_Email;

$subscriberClass = acymailing_get('class.subscriber');
$subid = $subscriberClass->save($myUser);

$newSubscription = array();
$newList = array();
$newList['status'] = 1;
$newSubscription[6] = $newList; // Replace 2 with the ID of the list.

$subscriberClass->saveSubscription($subid, $newSubscription);
}
 
Push

OK, I was able to get it to work with the Joomla User data. I tried it on another database by using using a new the method you indicated. I created a new table to add users and called it sk_add. In that table I added the elements you requested. Then I added the databasejoin field in a table called "soulkeeper". In the addon of the soulkeeper form, I added the below code. Can you tell me what I'm doing wrong?

$myAssignedId = '{soulkeeper___soulkeeper_raw}';
$myAssignedId = is_array($myAssignedId) ? $myAssignedId[0] : $myAssignedId;
$myVisitor = '{soulkeeper___name}';
$myPhone = '{soulkeeper___mobile}';
$myVis_Email ='{soulkeeper___email}';

if (!empty($myAssignedId)) {
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);
$myQuery->select('name, email, phone')->from('add_sk')->where('id = ' . $myDb->quote($myAssignedId));
$myDb->setQuery($myQuery);
$myAssignedId = $myDb->loadObject();

if (! include_once JPATH_ADMINISTRATOR . '/components/com_acymailing/helpers/helper.php')
{
throw new RuntimeException("Acymailing not installed");
return false;
}

$myUser = new stdClass();
$myUser->email = $myAssignedId->get email;
$myUser->name = $myAssignedId->get name;
$myUser->skphone = $myAssignedId->get phone;
$myUser->visitor = $myVisitor;
$myUser->phone = $myPhone;
$myUser->visemail = $myVis_Email;

$subscriberClass = acymailing_get('class.subscriber');
$subid = $subscriberClass->save($myUser);

$newSubscription = array();
$newList = array();
$newList['status'] = 1;
$newSubscription[6] = $newList; // Replace 2 with the ID of the list.

$subscriberClass->saveSubscription($subid, $newSubscription);
}
 
I really can't tell by just looking at your code. Is it throwing errors on submit?

If it isn't throwing any obvious errors (make sure you have J! error reporting set to max) I'd have to log in and debug it and fix it for you, but that's going somewhat beyond the scope of standard support.

-- hugh
 
OK, it seems that your 'soulkeeper' element is a dropdown, with J! usernames hard coded into it. Which doesn't match your description of your of having an 'sk_add' table, or my suggestion of using the J! users table and restricting the options to just the users in a specific group. So that code is trying to load a J! user by name, which won't work, you have to use the numeric ID.

And btw, in the last code you quoted, you said your table is called sk_add, but in the code, in the select() you refer to it as add_sk.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top