This is an xml file with form element at root and then there is a nested fieldset element. Fieldset elements could be more than one, but currently in our case, it is one. We are starting up with an id field. Every field would have a name and type, which will uniquely identify it. So, in this form you will notice hidden elements, text elements, lists, radio button etc. After that there would be label and description for every form element. If the element type is not “hidden”, the label will be displayed right before it and description will be displayed, when you mouse over the label. Then there are other parameters like size, default and class and are doing the same as their nmae propose. Elements could also be marked as required. JForm ensures that a value must be set for that element, which is marked as required.
The next field is the “access” field which is given a type of “accesslevel”. This will give us a list of the viewing access levels that are defined in the user manager.
// No direct access
defined('_JEXEC') or die;
class BreedViewBreed extends JViewLegacy
public function display($tpl = null)
$this->state = $this->get('State');
$this->item = $this->get('Item');
$this->form = $this->get('Form');
// Check for errors.
if (count($errors = $this->get('Errors')))
throw new Exception(implode("\n", $errors));
protected function addToolbar()
$user = JFactory::getUser();
$isNew = ($this->item->id == 0);
$checkedOut = !($this->item->checked_out == 0 || $this->item->checked_out == $user->get('id'));
$checkedOut = false;
$canDo = BreedHelper::getActions();
// If not checked out, can save the item.
if (!$checkedOut && ($canDo->get('core.edit') || ($canDo->get('core.create'))))
if (!$checkedOut && ($canDo->get('core.create')))
JToolBarHelper::custom('breed.save2new', 'save-new.png', 'save-new_f2.png', 'JTOOLBAR_SAVE_AND_NEW', false);
if (!$isNew && $canDo->get('core.create'))
JToolBarHelper::custom('breed.save2copy', 'save-copy.png', 'save-copy_f2.png', 'JTOOLBAR_SAVE_AS_COPY', false);
This is the actual view which will hold the form. In this view.html.php file like other views, first there is a view class in which lot of things are happening. On line 21, we are getting an item from the model. We already have a breed model in place, so we are getting it from there. Next there is exception handling and after that there is a call to addtoolbar method, which will add the toolbar to the form view. In the toolbar method, we have function calls to JToolBarHelper for Apply, Save and Close, Save and New, Save and Copy, Cancel respectively.
On line 22, we are adding a form to the view, by getting a form from the model and sending it to the view. We are assigning this form value to the $form property, we have declared on line 16. Next step is to add that form to layout.
In the toolbar method, the first line at 38, we are trying to hide the main menu, by passing a variable in the request,name as “hidemainmenu”. The main drop down menu in the backend is a module and through “hidemainmenu” it could be disabled. set(‘hidemainmenu’, true) works like we have included this variable in the url and as component code runs first, it provides information to template, to hide a module, otherwise which it is going to display.
Next we take some measures to see which toolbar buttons we can display. Ee add the “apply”, “save” and “save-to-new” buttons, if the record is not checked out, and the user has the “core.edit” permission. Now, if the record already exists, and the user has the “core.create” permission we add the “save-to-copy” button. After that, we add a cancel button to toolbar and if we are editing an existing record, we change the label from “cancel” to “close”.
Instead of default.php, this file is edit.php and the reason for this is, joomla is using this mechanism as a way of securing this view against unauthorized access to add or edit records.
In this file we have a form, starting from line 40 which is posting back to breed component and we also have a breed item id, embedded into the form which tells joomla that we are dealing with this specific record.
To load three core behaviours, we are using JHtml class here, which will enable us to display tooltips, second will validate the html form and the third will keep the form alove, when we are performing edits to it.
It is the beauty of Joomla JFormField that you can create any form field type and add it to your Joomla extension, by just extending JFormField base class and providing appropriate field type. In our case here, we are trying to create a multiple select field, through which multiple images could be uploaded. In this file, first we have imported the formfield library and then have created the class “JFormFieldFileMultiple” extending JFormField. In the getInput method, we have declared a multiple form field and passed it to $html variable, which will be returned back. Note that the name of the field is dynamic, as it will be picked from the form XML file, through JFormField class.
I basically work in the CMS, like Joomla and WordPress and in framework like Laravel and have keen interest in developing mobile apps by utilizing hybrid technology. I also have experience working in AWS technology. In terms of CMS, I give Joomla the most value because I found it so much user freindly and my clients feel so much easy to manage their project in it.
Enjoy best web development services at an affordable price. Looking forward to build a good relationship and serve you better...
My name is Nohman Habib and I am a web developer with over 10 years of experience, programming in Joomla, Wordpress, WHMCS, vTiger and Hybrid Apps. My plan to start codingace.com is to share my experience and expertise with others. Here my basic area of focus is to post tutorials primarily on Joomla development, HTML5, CSS3 and PHP.