J3.x

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

From Joomla! Documentation

< J3.x:Creating a simple module
(Created page with "''Let op:'' De formulierveld parameters worden voor elke module opgeslagen als json-encoded string in de #__modules tabel, onder het params veld.")
(Created page with "Nu gaan we het formulierveld iets laten doen!")
Line 27: Line 27:
 
''Let op:'' De formulierveld parameters worden voor elke module opgeslagen als json-encoded string in de #__modules tabel, onder het params veld.
 
''Let op:'' De formulierveld parameters worden voor elke module opgeslagen als json-encoded string in de #__modules tabel, onder het params veld.
  
Now lets make the form field do something!
+
Nu gaan we het formulierveld iets laten doen!
  
 
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.
 
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.

Revision as of 10:36, 6 July 2015

Other languages:
Bahasa Indonesia • ‎Deutsch • ‎English • ‎Nederlands • ‎español • ‎français • ‎português • ‎русский • ‎中文(台灣)‎
Joomla! 
3.x
Handleiding
Een eenvoudige module maken

Dit is een serie artikelen over het ontwikkelen van een module voor Joomla! versie Joomla 3.x. U kunt navigeren binnen de artikelen in deze serie met behulp van het navigatie drop-down menu.

Begin met de Introductie en navigeer door de artikelen van de serie door middel van de navigatieknop onderaan of het vak rechts (Artikelen in deze serie). Er zitten 2 video's bij deze handleiding die u hier kunt zien Basic Joomla Module Development video 1 en Basic Joomla Module Development video 2.




Formuliervelden creëren een grote mate van maatwerk in Joomla. Ze zijn de enige manier waarop gebruikers de module aan de eisen van hun site kunnen aanpassen.

Formuliervelden toevoegen aan de module

In this case we are going to extend our previous example using the database to provide a list of languages for the user to select from. To allow this to happen we will use the SQL form field type (full details for this on the SQL Form Field docs page).

Allereerst voegen we een formulierveld toe aan ons xml-bestand. Weet u nog dat we in config tags hebben toegevoegd? In die tags voegen we de volgende code toe:

<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.

Als u de module zou installeren zoals hij nu is en er in de Joomla backend naar kijkt, zou u zien dat er een dropdown verschijnt (hoewel een optie kiezen op dit moment nog geen effect heeft op de module).

Let op: De formulierveld parameters worden voor elke module opgeslagen als json-encoded string in de #__modules tabel, onder het params veld.

Nu gaan we het formulierveld iets laten doen!

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.