User

Difference between revisions of "Over/Step by step to a Joomla Module - A form and ajax"

From Joomla! Documentation

< User:Over
Line 57: Line 57:
 
We have to add the language strings to the .ini file
 
We have to add the language strings to the .ini file
  
==== mod_yourmodule.ini Form texts ====
+
==== en-GB.mod_yourmodule.ini Form texts ====
  
 
<source>
 
<source>
  
 
</source>
 
</source>

Revision as of 06:34, 18 August 2014

J3x module tutorial.jpg

Introduction[edit]

This is a multiple article series on how to develop a module for Joomla! version Joomla 3.x. We go step by step from basic functionality to some more advanced. At the end of the tutorial we'll use your custom module to show you, how you can use the powerful output override ( = change ) methods provided by Joomla!. Navigate the articles in this series by using the navigation box to the right (the Articles in this series). Start with the first and follow them one by one. The next article builds on the knowledge and the files from the previous.

A Tip!

As the links on this page are references, you should open them in a new browser window/tab.

In this part of the tutorial we will use the form functionality of Joomla!. In a second step we'll add the Joomla! Ajax functionality to the module. If you want to keep the custom module you created up till now, you should use the knowledge you've got from this tutorial and fork it. i.e. you copy all the files to a new local folder and change all filenames to a new name. Then you change all texts in the files including the old module name to a your new. We will still use yourmodule as name so you'll have to adopt your own as before.

A Tip!

We will not mention the name adoption anymore.

If you have a MVC component related to your module, it's easier to include the form functionality a.k.a. JForm. We'll add it without a component.

We first need a xml form declaration. In the folder where you unzipped the downloaded file you can find a models folder. Copy this to your modules web 'root' folder. A module doesn't follow the MVC pattern, but let us use models as folder name. For a component you'll find forms, fields and rules in this path.

Open models/forms/yourmodule_form.xml for edit.

yourmodule_form.xml[edit]

<?xml version="1.0" encoding="utf-8"?>
<form>
   <fieldset addfieldpath="modules/mod_yourmodule/models/fields"
             addrulepath="modules/mod_yourmodule/models/rules">  
      <field name="subject"
         type="text"
         size="60"
         description="MOD_YOURMODULE_MESSAGE_SUBJECT_DESC"
         label="MOD_YOURMODULE_MESSAGE_SUBJECT_LABEL"
         filter="string"
         validate="yourmodulemessagesubject"
         required="true"/>
      <field name="message"
         type="textarea"
         cols="50"
         rows="10"
         description="MOD_YOURMODULE_ENTER_MESSAGE_DESC"
         label="MOD_YOURMODULE_ENTER_MESSAGE_LABEL"
         filter="safehtml"
         validate="yourmodulemessage"
         required="true"/>
   </fieldset>
   <fieldset name="captcha">
      <field
         name="captcha"
         type="captcha"
         label="MOD_YOURMODULE_CAPTCHA_LABEL"
         description="MOD_YOURMODULE_CAPTCHA_DESC"
         validate="captcha"
         namespace="contact"/>
   </fieldset> 
</form>

To be able to use our own fields and rules we add 'addfieldpath' and 'addrulepath'. Explaning the deatails of the declarations would be to much for this tutorial. Only so far: we add two fields 'subject' and 'message'. We also add a captcha to be used in the form.

The language strings[edit]

We have to add the language strings to the .ini file

en-GB.mod_yourmodule.ini Form texts[edit]