1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice

$opt->value: explode using separator in a dbjoin element

Discussion in 'Community' started by mirceat, Jan 28, 2020.

  1. mirceat

    mirceat Member

    Level: Community
    Hello

    can i explode $opt->value using a delimiter and populate a dbjoin element with the array values? I'm using a dbjoin because the values are dinamically retrieved from database.

    Let's say the $opt->value looks like (string) "value1|value2|value3". I tried to convert this string to array using explode and populate the dbjoin options, but all i can get is value = "value3", label = "value3"

    Code (Text):

    $tests = explode("|",$opt->value);
    foreach ($tests as $test) {
    $opt->value = $test;
    $opt->text = $test;
    }
     
    How can i populate the dbjoin element like:

    <select name"..">
    <option value="value1">value1</option>
    <option value="value2">value2</option>
    <option value="value3">value3</option>
    </select>

    Thank you
     
  2. troester

    troester Well-Known Member Staff Member

    Level: Community
    You could use a dropdown element populated via "Advanced".
     
  3. mirceat

    mirceat Member

    Level: Community
    Can i retrieve dynamic values in a dropdown? If yes, how?
    The dbjoin element is using a where condition like "where {thistable}.id = '{table___elementname}'", i tried with a query in dropdown but it's not working, the placeholder value is not retrieved..
     
  4. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    We should be doing a placeholder replacement on your code, but you may be better off finding it yourself, with something like ...

    Code (Text):

    $formModel = $this->getFormModel();
    // form data should be in $formModel->data, you can test by dumping it out here ...
    var_dump($formModel->data); exit;
     
    -- hugh
     
  5. mirceat

    mirceat Member

    Level: Community
    I'm still confused: how can i retrieve the data dinamically from another element using dropdown and php code as troester says above?

    I tried with placeholder (the value is not retrieved dinamically as oposite to dbjoin element where an ajax call is triggered) and also using formModel (didn't know that i can use it in elements, not only for php form plugin), i can't make it work..

    Let's say i have the following php code in the Advanced tab for a dropdown:

    Code (Text):

    $formModel = $this->getFormModel();
    $user_id = $formModel->data['test___user_raw'][0]; //test___user is an "user" element
    $db = JFactory::getDbo();
    $db->setQuery('SELECT id, name as text FROM #__users where id = '.$user_id.'');
    $rows = $db->loadObjectList();
    foreach ($rows as $row) {
        $options[] = JHTML::_('select.option', $row->id, $row->text);
    }
    return $options;
    When i load the form, I'm already selected in dropdown. So far so good, the value is retrieved from the test___user element.

    But soon as i choosed another User from test___user, the dropdown option is not dinamically updated. That's why i choosed dbjoin element and asked how to split the $opt->value..

    Thank you
     
  6. troester

    troester Well-Known Member Staff Member

    Level: Community
    You should set up your dbjoin list as a "clean" lookup table, already with splitted values/text.
     
  7. mirceat

    mirceat Member

    Level: Community
    The dbjoin values will be added by specific users (Product Manager) in an existing form. Basically, the PM will add a simple value that will be autofilled in a field element displayed for agents or will add a "collection" of values that will be displayed in a dbjoin element for agents. It's like a form created by Super User that will be visible only for PM and all the values filled by PM will be displayed in another form for agents.

    In the end i will activate the Frontend option for dbjoin and ask PM to add the values here and fill a db table..never used this option before, let's hope it will solve my request.
     

Share This Page