0

hi i want to use com_media image selection in my own component. the link is:

index.php?option=com_media&view=images&tmpl=component&
e_name=smallimage

the image goes to editor while i want it's address go to

<input class="inputbox" type="text" name="smallimage" id="smallimage" size="40" 
maxlength="255" value="<?php echo $row->smallimage; ?>" title=
"<?php echo JText::_('SMALLIMAGETIP' ); ?>" />

i am using joomla 1.5

any suggestion?

thanks

amin
  • 621
  • 1
  • 8
  • 20

2 Answers2

3

If you're using Joomla 1.6 the easy way is let Joomla do all the work for you. How?

First you need to include in you xml form (/model/forms/YOURFORM.xml) something like that...

<field name="imageurl" type="media" directory="CUSTOMDIRECTORY?"
                hide_none="1" label="COM_YOURCOMPONENT_IMG_LABEL"
                size="40"
                description="COM_YOURCOMPONENT_IMG_DESCRIPTION" />

Haven't you got a getForm() in your model?

public function getForm($data = array(), $loadData = true)
    {

        // Get the form.
        try {
            //throw new Exception(JText::_('JLIB_FORM_ERROR_NO_DATA'));
            $form = $this->loadForm('com_kfiles', 'files');
        } catch (Exception $e) {
            echo "e";
            echo 'Caught exception: ',  $e->getMessage(), "\n";
        }

        if (empty($form)) {
            return false;
        }


        return $form;
    }

In your view (/views/xxxx/view.html.php) you need to load your form

$this->form = $this->get('Form');

Finally you only need to print the element in the template wherever you want.

echo $this->form->getLabel('imageurl'); 
echo $this->form->getInput('imageurl');

Bye

raultm
  • 706
  • 6
  • 20
  • as I can see this type="media" is new in 1.6 and still not documented. http://docs.joomla.org/Standard_parameter_types I use the Banners Component as a Guide. Maybe you can use a Joomla Component as a guide if you know where the Image Picker is used. – raultm Apr 12 '11 at 08:17
  • image selector is used under editor input box and advanced editor use it, problem is that it send the picture to "text area" covered by img tag, while i want it to select address and bring it as string in my input box. i edited related js file but no result! – amin Apr 12 '11 at 09:13
  • currently i'm working, if nobody answer til this afternoon I'll try to found your solution. – raultm Apr 12 '11 at 10:01
1

Not straight forward, but you can have work around as mentioned here - Joomla Forum

Shyam Verma
  • 501
  • 2
  • 9