J3.x

Difference between revisions of "Creating a simple module/Adding Form Fields/fr"

From Joomla! Documentation

< J3.x:Creating a simple module
(Created page with "Dans notre cas, nous allons étendre notre précédent exemple en utilisant la base de données pour fournir une liste de langues à sélectionner par l'utilisateur. Pour ce f...")
Line 4: Line 4:
  
 
== Ajouter des champs de formulaire au module ==
 
== Ajouter des champs de formulaire au module ==
Dans notre cas, nous allons étendre notre précédent exemple en utilisant la base de données pour fournir une liste de langues à sélectionner par l'utilisateur. Pour ce faire, nous allons utiliser  le type de champs de formulaire SQL (des détails complets sont disponibles sur la page [[S:MyLanguage/SQL_form_field_type|Champs de formulaire SQL ]]).
+
Dans notre cas, nous allons étendre notre précédent exemple en utilisant la base de données pour fournir une liste de langues à sélectionner par l'utilisateur. Pour ce faire, nous allons utiliser  le type de champs de formulaire SQL (des détails complets sont disponibles sur la page [[S:MyLanguage/SQL_form_field_type|champs de formulaire SQL ]]).
  
 
First of all we are going to add a form field into our xml file. Remember those config tags that we added in earlier? Well now inside these tags we are going to add the following code:
 
First of all we are going to add a form field into our xml file. Remember those config tags that we added in earlier? Well now inside these tags we are going to add the following code:

Revision as of 14:10, 1 July 2015

Other languages:
Bahasa Indonesia • ‎Deutsch • ‎English • ‎Nederlands • ‎español • ‎français • ‎português • ‎русский • ‎中文(台灣)‎
Joomla! 
3.x
Didacticiel
Création d'un module simple

Ceci est une série de plusieurs articles expliquant la façon de développer un module pour Joomla! Version Joomla 3.x. Vous pouvez naviguer dans les articles de cette série à l'aide du menu déroulant.

Commencez par l'Introduction puis naviguez dans les articles de cette série en utilisant soit les boutons de navigation situés en bas des articles, soit le menu droit (Les articles de cette série).




Form fields give a great deal of customisation in Joomla and for modules are the sole way of allowing the user to tweak the module to the needs of their site.

Ajouter des champs de formulaire au module

Dans notre cas, nous allons étendre notre précédent exemple en utilisant la base de données pour fournir une liste de langues à sélectionner par l'utilisateur. Pour ce faire, nous allons utiliser le type de champs de formulaire SQL (des détails complets sont disponibles sur la page champs de formulaire SQL ).

First of all we are going to add a form field into our xml file. Remember those config tags that we added in earlier? Well now inside these tags we are going to add the following code:

<fields name="params">
    <fieldset name="basic">
        <field
               name="lang"
               type="sql"
               default="1"
               label="Select a language"
               query="SELECT id AS value, lang FROM #__helloworld" />
    </fieldset>
</fields>

This selects the languages from the database table and allows the user to choose which one from a select element.

If you were to install the module as it is now you would see if you were to access the module in the backend of Joomla that a dropdown had appeared (although picking an option won't affect the module at the moment).

Note: The form field parameters are stored for each module in the #__modules table under the params field as json encoded string.

Now lets make the form field do something!

Lets go into the mod_helloworld.php and retrieve the parameter (note you cannot retrieve the parameter in the helper), and then pass it into the helper function.

/**
  * This retrieves the lang parameter we stored earlier. Note the second part
  * which states to use the default value of 1 if the parameter cannot be
  * retrieved for some reason
**/
$language = $params->get('lang', '1');
$hello    = modHelloWorldHelper::getHello( $language );

Now lets edit our database query in the helper file to reflect our parameter choice.

// Obtain a database connection
$db = JFactory::getDbo();
// Retrieve the shout - note we are now retrieving the id not the lang field.
$query = $db->getQuery(true)
            ->select($db->quoteName('hello'))
            ->from($db->quoteName('#__helloworld'))
            ->where('id = '. $db->Quote($params));
// Prepare the query
$db->setQuery($query);
// Load the row.
$result = $db->loadResult();
// Return the Hello
return $result;

Conclusion

Form fields give the user an easy way to customise the module to their sites settings. This allows the modules scope to be increased as well for many languages and applications.