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

placeholder for dropdown only return value,not label

Discussion in 'Community' started by samani, Jul 17, 2019.

  1. samani

    samani Member

    Level: Community
    hi
    i have a simple dropdown element that has some velue/lable such as 1/A 2/B 3/C ....
    i want get A or B or.... infact i want get label but it is return only value
    i use these syntax :
    Code (Text):

    $formModel->getElementData('registration___city');
    '{registration___city}'
     
    but in both syntax i get value of that dropdown element such as 1 or 2 ...
    how to get label of dropdown selected?
    i use these in php form plugin
     
  2. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Correct, you will only have the values available at that point. This is because the form itself only submits values. That's an HTML thing, not a Fabrik thing. Labels for dropdowns (and radios, and checkboxes) are only for display to the user, they don't get submitted with the form. So at that point, the labels are only stored in the settings of the element itself, they aren't in the submitted data. Later in the form processing, Fabrik will add the labels, during post-processing, so they are available for things like emails. But as it's a significant overhead to build all that rendered data, we don't do it during pre-processing (before the data is written to the table), as we don't need it at that point, and just want to get data written out as quickly as possible.

    I pretty much always use joins rather than dropdowns if I'm going to need to do any processing of my own, as that makes getting labels for values a lot easier, it's just straight forward table lookups, rather than having to worry about Fabrik's internal data representations, and how we store labels for values.

    However, you can get the labels, if you grab the element model. Something like ...

    Code (Text):

    $elementModel = $formModel->getElement('yourtable___yourelement');
    $label = $elementModel->getLabelForValue($value);
     
    -- hugh
     
    samani likes this.
  3. samani

    samani Member

    Level: Community
    i see the dumped $formmodel (with jdump extension) and i can see the label of city and get with this syntax:
    Code (Text):

    $formModel->emailData['registration___city']
     
    it is work and return label of city drop down field
    am i correct? is there anyproblem with do this?
    can you say me what syntax i can use to get label when you use join element?
     
  4. troester

    troester Well-Known Member Staff Member

    Level: Community
    With a dbjoin '{registration___city}' should do (value is in '{registration___city_raw}'
     
    samani likes this.
  5. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    What hook are you running the PHP plugin on? Like 'onBeforeProcess', 'onAfterProcess', etc.

    -- hugh
     
    samani likes this.
  6. samani

    samani Member

    Level: Community
    Start of submission (onbeforeprocess)
    Is it different or is there any tip? Maybe in future i want to change that.
     
  7. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    OK, then you probably have something like a calc element on the form.

    Typically, the $formModel->emailData array is not populated until 'onAfterProcess'. But certain elements (calc being one of them) will kick off the $formModel->getEmailData() method, causing all elements to render their formatted values, during the pre-processing phase.

    The array name is a little inaccurate, for historical reasons. It's basically the rendered element data, more or less as it would appear in a list view, or details view ... or in an email. It was originally only used by the email plugin, back in Fabrik 1.x, hence the name.

    So yeah, if that array is populated, go ahead and use it. Just note that if you ever remove whichever element is triggering the formatting process, that data may disappear and you'll have to trigger it yourself.

    -- hugh
     
    samani likes this.

Share This Page