Skip to content

Instantly share code, notes, and snippets.

@coolbung
Created May 27, 2016 16:14
Show Gist options
  • Save coolbung/dd363e8cf2b58b3df6f9f9335efc1984 to your computer and use it in GitHub Desktop.
Save coolbung/dd363e8cf2b58b3df6f9f9335efc1984 to your computer and use it in GitHub Desktop.
Loading JForm field programatically
<?php
// No direct access
defined('_JEXEC') or die;
//Get custom field
JFormHelper::addFieldPath(JPATH_COMPONENT . '/models/fields');
$media_dummy = JFormHelper::loadFieldType('MediaUpload');
$element_init = simplexml_load_string('<field name="dummy" type="mediaupload" mediaType="image" required="true"
accept="image/*" initCode="true" />');
$media_dummy->setup($element_init, '');
$media = JFormHelper::loadFieldType('MediaUpload');
$element = simplexml_load_string('<field name="image" type="mediaupload" mediaType="image" required="true"
accept="image/*" />');
$media->setup($element, '');
echo $media_dummy;
echo $media;
@manojLondhe
Copy link

manojLondhe commented May 28, 2016

This needs to be changed from
echo $media_dummy;
to
echo $media_dummy->getInput();

Also, getInput this needs to be public function in the field file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment