(SOLVED )Populate Field element after Databasejoin Selected

jmoises

Active Member
Hi, so i seach on the forum and didnt find something similar,

I was using a CALC element and with Ajax calculation = TRUE, and some PHP code to retrive data from a table, depending the databasejoin element selection, was working fine, but CALC element dosent allow to edit the data, so i change the CALC element to a FIELD element and using eval = true and the php code, but my problem is that FIELD elelemt is not AJAX ready so if the user change the Databasejoin the FIELD element is not read again the php code ....

I hope somebody can give me the aproch or advise how can i do this.

Thank you
 
You can use the same approach as in your other just recently solved thread.

In databasejoin element's javascript "change" event add the Ajax call to a function in user_ajax.php. Then, in that ajax call "done" function, update your field element with the retrieved value.
 
Last edited:
You can use the same approach as in your other just recently solved thread.

In databasejoin element's javascript "change" event add the Ajax call to a function in user_ajax.php. Then, in that ajax call "done" function, update tour field element with the retrieved value.

Yes, thank you i have never user ajax with fabrik so this will solve so many questions that i have, basicaly Fabrik, joomla and some help what can you do is inlimited!!! thanks again for the answer!
 
Yes, thank you i have never user ajax with fabrik so this will solve so many questions that i have, basicaly Fabrik, joomla and some help what can you do is inlimited!!! thanks again for the answer!

This might be exactly what I'm looking for. Would you be able to tell me exactly what the solution was. I'm not too Javascript savvy.
 
Nevermind! Figured it out. This is great.

For the field element, I used inline JS

Code:
var uid = this.form.formElements.get('afab_bc___member_name').getValue();

jQuery.ajax({
    url: 'https://www.whatever.com/index.php?option=com_fabrik&format=raw&task=plugin.userAjax&method=LegalName&userid='+uid,
    method: 'get',
    context: this
}).done(function (myresult) {
   var UsersLegalName = this.form.formElements.get('afab_bc___legal_name');
   UsersLegalName.update(myresult);
});

Then, you need to go to components/com_fabrik
Locate user_ajax_example.php
Copy user_ajax_example.php and rename it user_ajax.php as a starting point

and for user_ajax.php I added the following terrible function:

Code:
    public function LegalName()
    {

    $app = JFactory::getApplication();
    $input = $app->input;
    $userid = $input->get('userid', '');
  
    $int = (int)$userid;
    $myDb = JFactory::getDbo();
    $myQuery = $myDb->getQuery(true);
    $myQuery->select('first_name')->from('jos_acymailing_subscriber')->where('userid = ' . $int);
    $myDb->setQuery($myQuery);
    $fname = $myDb->loadResult();
    $myQuery = $myDb->getQuery(true);
    $myQuery->select('last_name')->from('jos_acymailing_subscriber')->where('userid = ' . $int);
    $myDb->setQuery($myQuery);
    $lname = $myDb->loadResult();
    echo $fname . ' ' . $lname;
    }

Then after two and a half days of tinkering on and off with this, I smashed my keyboard repeatedly on my forehead screaming "LET'S GOOOOO". Have a great weekend.
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top