1.5 Template Project

The Joomla! Documentation Working Group is running a project to develop detailed reference and tutorial material on Joomla! 1.5 templates.  There is a project page on the documentation wiki where you can see the work in progress and help us by contributing your knowledge.

Who's Online

We have 4 guests online

Help Site License

The Joomla! Help Site content is copyright © 2005 - 2008 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution NonCommercial ShareAlike 2.5. Some parts of this website may be subject to other licenses.
Home arrow Developer Manual arrow 11. API Reference arrow mosGetParam

mosGetParam PDF Print E-mail

Last reviewed: 17 Nov 2005, Joomla 1.0.3
phpDocumentor

mosGetParam is a frequently used function in Joomla components and modules.  It allows you to easily retrieve the value of a parameter passed from a previous page, for example, from filling in a form or clicking on a link.  By default the data returned will be stripped of HTML tags and will have leading and trailing whitespace characters removed.

If magic_quotes_gpc is off then mosGetParam will automatically escape single quotes, double quotes, backslashes and nulls by adding a backslash character (unless the _MOS_ALLOWRAW option is used). Note that with magic_quotes_gpc on all entries in $_ENV, $_GET, $_POST, $_REQUEST, $_COOKIE, $_GLOBALS and $_SERVER arrays are automatically escaped by PHP. This behaviour is not overridden by using the _MOS_ALLOWRAW flag. See also magic quotes in the PHP manual.

Note that if you intend to store the data returned by a mosGetParam call in a database field then you will need to perform additional database-specific escaping. See database->getEscaped.

Syntax

mixed mosGetParam ( array &$arr, string $name [, mixed $default [, int $mask ]] )

$arr
is the array that the parameter will be retrieved from.  This can be any array but the most commonly used ones are $_POST and $_GET.
$name
is the name of the parameter field to be retrieved.
$default
is the optional default value that will be returned if $name is not present in $arr.  This parameter is optional and if omitted will default to null.
$mask
is an optional parameter containing one or more of the following flags:
_MOS_ALLOWHTML
Do not strip HTML tags from the data.
_MOS_NOTRIM
Do not remove leading and trailing whitespace characters.
_MOS_ALLOWRAW
Do not filter the data.  Introduced in Joomla 1.0.
If omitted this parameter defaults to 0 (that is, data will be stripped of HTML tags and leading and trailing whitespace characters).

Defined in

libraries/joomla/functions.php
(includes/joomla.php prior to Joomla 1.1)
(includes/mambo.php prior to Joomla 1.0)

Examples

Example 1: A typical use where the parameter 'task' is retrieved from the set of parameters passed in a URL from a previous page.  If 'task' is not present then $task will be set to an empty string.

// Get task value.
$task = mosGetParam( $_GET, 'task' );
echo $task;

Example 2: Force an expected integer to be an integer (wth a default value of zero).

// Get an integer.
$id = intval( mosGetParam( $_REQUEST, 'id', 0 ) );
echo $id;

Please report any errors on this page to the Developer Documentation Forum.

Last Updated ( Tuesday, 03 January 2006 )
 
< Prev   Next >