You may have noted that the html form contained in the ''[[#admin/views/helloworld/tmpl/edit.php|admin/views/helloworld/tmpl/edit.php]]'' file now has the ''form-validate'' css class. And that we added a ''JHTML::_('behavior.formvalidation');'' call to tell Joomla!1.6 to use its javascript form validation.

+

You may have noted that the html form contained in the ''[[#admin/views/helloworld/tmpl/edit.php|admin/views/helloworld/tmpl/edit.php]]'' file now has the ''form-validate'' css class. And that we added a ''JHTML::_('behavior.formvalidation');'' call to tell Joomla to use its javascript form validation.

Modify the ''admin/models/forms/helloworld.xml'' file to indicate that the ''greeting'' field has to be verified:

Modify the ''admin/models/forms/helloworld.xml'' file to indicate that the ''greeting'' field has to be verified:

Verifying the form on the server side is done by inheritance of ''JControllerForm'' class. We have specified in the ''[[#admin/models/forms/helloworld.xml|admin/models/forms/helloworld.xml]]'' file that the validate server function will used a ''greeting.php'' file.

+

Verifying the form on the server side is done by inheritance of ''JControllerForm'' class. We have specified in the ''[[#admin/models/forms/helloworld.xml|admin/models/forms/helloworld.xml]]'' file that the validate server function will use a ''greeting.php'' file.

Create a compressed file of this directory or directly download the [http://joomlacode.org/gf/download/frsrelease/11394/58126/com_helloworld-1.6-part11.zip archive] and install it using the extension manager of Joomla!1.6. You can add a menu item of this component using the menu manager in the backend.

+

Create a compressed file of this directory or directly download the [http://joomlacode.org/gf/download/frsrelease/11394/58409/com_helloworld-1.6-part11.zip archive] and install it using the extension manager of Joomla. You can add a menu item of this component using the menu manager in the backend.

<span id="helloworld.xml">

<span id="helloworld.xml">

Line 401:

Line 408:

<source lang="xml">

<source lang="xml">

<?xml version="1.0" encoding="utf-8"?>

<?xml version="1.0" encoding="utf-8"?>

−

<extension type="component" version="1.6.0" method="upgrade">

+

<extension type="component" version="2.5.0" method="upgrade">

<name>COM_HELLOWORLD</name>

<name>COM_HELLOWORLD</name>

−

<!-- The following elements are optional and free of formatting conttraints -->

+

<!-- The following elements are optional and free of formatting constraints -->

<creationDate>November 2009</creationDate>

<creationDate>November 2009</creationDate>

<author>John Doe</author>

<author>John Doe</author>

Line 426:

Line 433:

</sql>

</sql>

</uninstall>

</uninstall>

−

<update> <!-- Runs on update; New in 1.6 -->

+

<update> <!-- Runs on update; New in 2.5 -->

<schemas>

<schemas>

<schemapath type="mysql">sql/updates/mysql</schemapath>

<schemapath type="mysql">sql/updates/mysql</schemapath>

Line 485:

Line 492:

== Navigate ==

== Navigate ==

−

+

[[Developing a Model-View-Controller (MVC) Component for Joomla!2.5 - Part 10|Prev: Adding decorations to the backend]]

−

[[Developing a Model-View-Controller (MVC) Component for Joomla!1.6 - Part 10|Prev: Adding decorations to the backend]]

You may have noted that the html form contained in the admin/views/helloworld/tmpl/edit.php file now has the form-validate css class. And that we added a JHTML::_('behavior.formvalidation'); call to tell Joomla to use its javascript form validation.

Modify the admin/models/forms/helloworld.xml file to indicate that the greeting field has to be verified:

Note for the moment that the css class is now "inputbox validate-greeting" and that the attribute required is set to true. It means that this field is required and has to be verified by a handler of the form validator framework of Joomla

It adds a handler to the form validator of Joomla for fields having the "validate-greeting" css class. Each time the greeting field is modified, the handler will be executed to verify its validity (no digits).

The final step is to implement a getScript function in the HelloWorldModelHelloWorld model:

admin/models/helloworld.php

<?php// No direct access to this filedefined('_JEXEC') or die('Restricted access');// import Joomla modelform library
jimport('joomla.application.component.modeladmin');/**
* HelloWorld Model
*/class HelloWorldModelHelloWorld extends JModelAdmin
{/**
* Returns a reference to the a Table object, always creating it.
*
* @param type The table type to instantiate
* @param string A prefix for the table class name. Optional.
* @param array Configuration array for model. Optional.
* @return JTable A database object
* @since 2.5
*/publicfunction getTable($type='HelloWorld',$prefix='HelloWorldTable',$config=array()){return JTable::getInstance($type,$prefix,$config);}/**
* Method to get the record form.
*
* @param array $data Data for the form.
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
* @return mixed A JForm object on success, false on failure
* @since 2.5
*/publicfunction getForm($data=array(),$loadData=true){// Get the form.$form=$this->loadForm('com_helloworld.helloworld','helloworld',array('control'=>'jform','load_data'=>$loadData));if(empty($form)){returnfalse;}return$form;}/**
* Method to get the script that have to be included on the form
*
* @return string Script files
*/publicfunction getScript(){return'administrator/components/com_helloworld/models/forms/helloworld.js';}/**
* Method to get the data that should be injected in the form.
*
* @return mixed The data for the form.
* @since 2.5
*/
protected function loadFormData(){// Check the session for previously entered form data.$data= JFactory::getApplication()->getUserState('com_helloworld.edit.helloworld.data',array());if(empty($data)){$data=$this->getItem();}return$data;}}

Verifying the form (server side)

Verifying the form on the server side is done by inheritance of JControllerForm class. We have specified in the admin/models/forms/helloworld.xml file that the validate server function will use a greeting.php file.

Create a compressed file of this directory or directly download the archive and install it using the extension manager of Joomla. You can add a menu item of this component using the menu manager in the backend.

helloworld.xml

<?xmlversion="1.0"encoding="utf-8"?><extensiontype="component"version="2.5.0"method="upgrade"><name>COM_HELLOWORLD</name><!-- The following elements are optional and free of formatting constraints --><creationDate>November 2009</creationDate><author>John Doe</author><authorEmail>john.doe@example.org</authorEmail><authorUrl>http://www.example.org</authorUrl><copyright>Copyright Info</copyright><license>License Info</license><!-- The version string is recorded in the components table --><version>0.0.11</version><!-- The description is optional and defaults to the name --><description>COM_HELLOWORLD_DESCRIPTION</description><install><!-- Runs on install --><sql><filedriver="mysql"charset="utf8">sql/install.mysql.utf8.sql</file></sql></install><uninstall><!-- Runs on uninstall --><sql><filedriver="mysql"charset="utf8">sql/uninstall.mysql.utf8.sql</file></sql></uninstall><update><!-- Runs on update; New in 2.5 --><schemas><schemapathtype="mysql">sql/updates/mysql</schemapath></schemas></update><!-- Site Main File Copy Section --><!-- Note the folder attribute: This attribute describes the folder to copy FROM in the package to install therefore files copied in this section are copied from /site/ in the package --><filesfolder="site"><filename>index.html</filename><filename>helloworld.php</filename><filename>controller.php</filename><folder>views</folder><folder>models</folder><folder>language</folder></files><mediadestination="com_helloworld"folder="media"><filename>index.html</filename><folder>images</folder></media><administration><!-- Administration Menu Section --><menuimg="../media/com_helloworld/images/tux-16x16.png">COM_HELLOWORLD_MENU</menu><!-- Administration Main File Copy Section --><!-- Note the folder attribute: This attribute describes the folder to copy FROM in the package to install therefore files copied in this section are copied from /admin/ in the package --><filesfolder="admin"><!-- Admin Main File Copy Section --><filename>index.html</filename><filename>helloworld.php</filename><filename>controller.php</filename><!-- SQL files section --><folder>sql</folder><!-- tables files section --><folder>tables</folder><!-- models files section --><folder>models</folder><!-- views files section --><folder>views</folder><!-- controllers files section --><folder>controllers</folder></files><languagesfolder="admin"><languagetag="en-GB">language/en-GB/en-GB.com_helloworld.ini</language><languagetag="en-GB">language/en-GB/en-GB.com_helloworld.sys.ini</language></languages></administration></extension>