0

I'm building a component with payment plugins and I need to display the plugins fields in the account form record.

The plugin xml fields section is

<fields name="params">
        <fieldset name="basic">
            <field name="paypal_email" type="email" default="" label="plg_mycomponent_paypal_email" description="plg_mycomponent_paypal_email_desc"  />
            <field name="paypal_image" type="media" default="" label="plg_mycomponent_paypal_image" description="plg_mycomponent_paypal_image_desc" filter="safehtml" />
        </fieldset>
    </fields>

I need to display the paypal_email and paypal_image fields in the account form and to have the possibility to save the values in account table.

How I can do that?

I try to achieve that with a "template" php file in the plugin to display the fields but it's not working.

1
  • Hi Jeremie, please add more details and try to clarify what you are trying to do. Personally I am confused by reading your question.
    – FFrewin
    Mar 4, 2020 at 8:39

1 Answer 1

0

Ok I applied this tutorial

and now it's working.

I load an xml file in the form with plugin event that I fire in the view.html.php and bind the form. I also modify the account model functions "save" and "loadFormData" because I'm saving the values in JSON format.

the plugin event to load fields to form

function addParamsToForm($form, $data) {
    $app = JFactory::getApplication();
    $option = $app->input->get('option');

    switch ($option) {
        case 'com_mycomponent' :
            if ($app->isClient('administrator')) {
                JForm::addFormPath(__DIR__ . '/forms');
                $form->loadFile('params', true);
                foreach ($form->getFieldset('paypal') as $field) {
                    $form->bind($data["paypal"]);
                }
            }
            return true;
    }
    return true;
}

and the /forms/params.xml file in the plugin

<?xml version="1.0" encoding="UTF-8"?>
<form>
<fields>
    <fieldset name="paypal">
        <field name="paypal_email" type="email" default="" label="plg_mycomponent_paypal_email" description="plg_mycomponent_paypal_email_desc"  />
        <field name="paypal_image" type="media" default="" label="plg_mycomponent_paypal_image" description="plg_mycomponent_paypal_image_desc" filter="safehtml" />
    </fieldset>
</fields>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.