I'm currently working on a custom field, where I manually add a checkbox to a file upload field. PDF Upload field
In onContentBeforeSave I want to read this checkbox to decide what to do with the file upload. I figured out to get the checkbox with
$jinput->post->getArray()['jform']['com_fields'][$fieldname.'_choverride']
It works, but I thought it's a pretty ugly call.
Is there a nicer, better way to do this?
Edit: Other solutions
Solution 2
$choveride_res = $postData->getArray(array(
'jform' => array(
'com_fields' => array(
$fieldData["fieldName"] . '_choverride' => 'string'
)
)
));
$res = $choveride_res['jform']['com_fields'][$fieldData["fieldName"] . '_choverride'];
Solution 3
$postData = JFactory::getApplication()->input->post;
$jform = new JRegistry($postData->get('jform', null, 'array'));
$comFields = new JRegistry($jform->get('com_fields', null, 'array'));
$choveride = $comFields->get($fieldData["fieldName"] . '_choverride', '', 'string');
onContentBeforeSave
rather than data from input. Since the plugin is meant to be usable across multiple components, form control (jform
) should not be hardcoded as it is configurable.com_fields
but this would be done inonCustomFieldsPrepareDom
. Both inputs (upload and override checkbox) should be a part of the XML form definition (currently the checkbox only appears in HTML markup). One way is to use subform (likeFields - Repeatable
) or similar approach.