how to upload multiple image in my backend component joomla form - joomla

I am developing a component in J! 2.5 and want to add a browse button on the backend so the user can pick a file they have previously uploaded but when I use a media type in the form.xml I can upload only one picture.
I use the code below in a xml file but I can upload only one picture?
How would I go about this?
<field name="image"
type="media"
label=""
description=""
class="inputbox"
/>

In your XML you have to define new element
<field name="image" type="myelement" label="" description="" class="inputbox" />
Now create file models/fields/myelement.php If you use XML file to load form from models/forms/myform.xml it will be found automatically. If not add attridute to <fieldset> parent element
addfieldpath="/components/com_custom/models/fields/"
Now in that file create class.
<?php
defined('_JEXEC') or die();
jimport('joomla.html.html');
jimport('joomla.form.formfield');
class JFormFieldMyelement extends JFormField
{
public $type = 'Myelement';
public function getInput()
{
}
}
Now return whatever you want. You can incorporate any 3d party uploader. For examples what to return in getInput() start typing JFormField and you will see in dropdown available classes.

Related

Code Ingiter POST data empty

I'm just have a trouble when POST a multipart form with codeigniter. The form is contain text field and 8 field of file upload. the problem is, the file is uploaded successfully with no error, but the field of text is empty in my controller.
I tried to print_r the POST data and get an empty array. But sometimes when I'm using google chrome, It's not got any problem.
Any solution?
<form name="form" action="some action page.php" method="post" enctype="multipart/form-data">
<input type="text" name="inputfieldvalue" value="Input Field">
<input type="file" name="uploadedfile" id="uploadedfile">
<input type="submit" value="Submit" >
</form>
// suppose your form is like this as above then to check textfield value
<?php echo $_POST['inputfieldvalue']; ?>
// pass the name attribute whatever you have given to $_POST[your name field value]. like this
Complete example should be working.
your form target action to function my_form in My_controller controller. Lest try input with name WTF
<form name="form" action="my_controller/my_form" method="post" enctype="multipart/form-data">
<input type="text" name="WTF" value="Input Field">
<input type="submit" value="Submit" >
</form>
your cotroller action in My_controller.php file (CI Controller folder) should look le this
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class My_controller extends CI_Controller {
function __construct() {
parent::__construct();
}
public function index(){
/* do something for page my_controller if you want */
} // end of index
function my_form() { // = my_controller/my_form
$here_is_it = $this->input->post('WTF'); // call value of input with name WTF
/* test it */
print_r($here_is_it);
}
Extra, to make sure everything it's okay. You can Enable auto load feature in Codeigniter. follow this tutorial
I Just check it for a while and the problem is not in the php or my html form code. But the problem is in my php.ini config. By increase upload max file size fix the problem. I just confused before because the form sometime work well and sometimes give an empty value.
Thanks in advance

How to add promotional labels on top of images in Magento 2 ?

How can I place a promotional label layer on top of images in Magento 2. The image I am including is from the out of the box Magento 2 theme and it has a text " New Luma Yoga Collection ...." and a button "Shop New Yoga" that was somehow placed on top of the image in the editor .
This is how it looks in the editor
There are various ways on how you can achieve this. One way is to add a HTML element directly into the WYSIWYG editor and mark it up with HTML. This is also how the Luma theme has done this. If you look at your editor, you see the content in small blue below the image. If you switch from WYSIWYG to HTML, you can see the HTML markup of this element:
<span class="content bg-white">
<span class="info">New Luma Yoga Collection</span>
<strong class="title">Get fit and look fab in new seasonal styles</strong>
<span class="action more button">Shop New Yoga</span>
</span>
You can simply use CSS to style this element.
However...
Although this is a very widely uses approach to do such a thing (and it's easy and fast to do so), it's not the most elegant solution. After all, it's not clear from the WYSIWYG-editor that the 'blue link' is actually a special element. If your client starts messing with it, he will break the layout and call you because 'you made the site, so it's your fault'. Trust me, I've been there...
A more elegant solution would be to use widgets. A widget is very simple to create in Magento 2. First you have to create a file called widget.xml in the etc-folder of your module, and put something like this in it:
<?xml version="1.0"?>
<widgets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Widget:etc/widget.xsd">
<widget id="example_widget" class="Vendor\Module\Block\Widget\Example">
<label translate="true">Example widget</label>
<description translate="true">This is an example widget</description>
</widget>
</widgets>
Now you can create a Block in the Block-folder of your module:
use Magento\Framework\View\Element\Template;
use Magento\Widget\Block\BlockInterface;
class Example extends Template implements BlockInterface
{
/**
* #return string
*/
public function _toHtml()
{
return '<p class="hello">Hello world!</p>';
}
}
Now if you click the widget-button in the WYSIWYG-editor, the widget will be there in the list of widgets to choose from:
Now, if you insert this widget in your WYSIWYG editor, you're sure about the HTML it will output (since that is handled with PHP), and your client cannot 'break it'.
In your scenario you most likely want to add parameters so you can make your widget reusable. This is very simple. Edit your widget.xml:
<widget id="example_widget" class="Vendor\Module\Block\Widget\Example">
<label translate="true">Example widget</label>
<description translate="true">This is an example widget</description>
<parameters>
<parameter name="name" xsi:type="text" visible="true" sort_order="0">
<label translate="true">Name</label>
<description translate="true">Please enter a name</description>
</parameter>
</parameters>
</widget>
And to use it in your Block Class:
public function _toHtml()
{
return '<p class="hello">Hello ' . $this->getName() . '</p>';
}
It's really that simple.
In your specific case I would suggest creating a widget with 4 parameters:
Header
Content
Button Text
Button Link

Custom HTML in Joomla Template Manager

While developing a Joomla Template, i got stuck on this question.
Every Joomla Module has a manifest. In that manifest you can set your Paramaters for your template with Field and Fieldset types. Is it possible to add a custom image in these sections? I tried CDATA for this but it doesn't work.
I've never tried this with a template, only a plugin and module, but I believe it's still the same concept.
Create a new folder in your template folder and name it "elements".
Then, in your template.xml file, find the <fieldset> that the parameter belongs to and add the following inside the tag:
addfieldpath="/modules/mod_social_slider/fields"
You now need to add a new parameter field like so:
<field name="image" type="custom" default="" label="" description="" />
Now, create a new PHP and place it inside your newly created "elements" folder and call it "custom.php". Then add the following code:
<?php
defined('_JEXEC') or die('Restricted access');
class JFormFieldCustom extends JFormField {
protected $type = 'Custom';
protected function getInput() {
return '<img src="' . JUri::root() . 'templates/your_template/images/image.jpg" alt="" />';
}
}
?>
Note that I haven't tested this so let me know if it works or not

refresh page with joomla component

I have a simple form in my tmpl/default.php:
<form id='AddForm' action="<?php echo JRoute::_('index.php?option=com_mycomponent&task=addcam'); ?>" >
<p>
<label for="CamName">Name:
</label>
<input type="text" id="CamName" name="cam_name" />
</p>
<button type='submit' class='submit_cam' name='addcam' value='Add'>Add</button>
<button type='reset' class='cancel_changes' name='cancel_changes' value='Cancel'>Cancel</button>
</form>
In my controller.php file I'm trying to process the values:
function addcam()
{
$add_name=JRequest::getString('cam_name');
$model = &$this->getModel();
$model->AddWebcam($add_name); //send to model to add to DB
}
In my model I just return the result of the query. With this implementation I just get routed to an empty page. I'd like to have it refresh the current page. Typically you do this with action="" but in my case I need it to route to the function called addcam in the controller. Or is there a better way to do this?
A common technique in Joomla when directing to the task is to have that function do a full redirect to a view at the end. This prevents a page refresh from trying to resubmit the data and leads to a cleaner url for the client. To do this, try the following:
function addcam()
{
$add_name=JRequest::getString('cam_name');
$model = &$this->getModel();
$model->AddWebcam($add_name); //send to model to add to DB
JFactory::getApplication()->redirect(JRoute::_(index.php?option=com_mycomponent&view=whatever));
}
Obviously, update the JRoute bit to the url you actually need. You can also include a message if you would like (like "Saved!"): http://docs.joomla.org/JApplication::redirect/1.6

Images in Magento widgets continued

I've been using Kus's answer found here:
Images in Magento widgets
However moving from my local to the testing server it looks like the class is not being read and I lose the button to upload.
This is my image block
<widgetpress_list type="springwidget_press/List" module="springwidget_press">
....
<image>
<label>Press Image</label>
<description>Image to be displayed on the page</description>
<visible>1</visible>
<type>label</type>
<helper_block>
<type>springwidget_press/imagechooser</type>
<data>
<button translate="open">
<open>Insert Image...</open>
</button>
</data>
</helper_block>
</image>
....
</widgetpress_list>
This is my class name in a file called app/code/local/Spring/Press/Block/ImageChooser.php
class Spring_Press_Block_ImageChooser extends Mage_Adminhtml_Block_Template
{
public function prepareElementHtml(Varien_Data_Form_Element_Abstract $element)
{
.
.
.
}
}
Any ideas?
I would not use a helper block but a custom field type.
Please have a look at my solution on Github. A sample implementation is available here.
An installation package is available on Magento Connect as well.

Resources