Retrieving and Filtering GET and POST requests with JRequest::getVar

When writing any web application, it is crucial that you filter input data before using it. Joomla! provides a filtering library to help you accomplish this.

You can access the filtered request data using the JRequest class. Even though PHP allows you to access the data from the request using the superglobal arrays $_GET, $_POST and $_REQUEST, it is highly recommended to use JRequestinstead of these superglobals. By using JRequest properly, you make sure that the data has the right format and its default value makes sense. This can prevent serious security holes such as SQL injection vulnerabilities.

Frequently, you will expect your variable to be found in a specific portion of the HTTP request (POST, GET, etc...). If this is the case, you should specify which portion; this will slightly increase your extension's security. If you expect 'address' to only be in POST, use this code to enforce that:

JREQUEST_ALLOWHTML - allows most HTML. If this is not passed in, HTML is stripped out by default.

Note. These are static variables not strings. Do not use quotes around them

'get'

To receive a whole array filtered. If you would want to get the POST data, you can use this.

JRequest::get('post')

This returns the standard POST array. You can use it on a template page if needed, or in the models section if convenient. It returns the most recent POST. Methods of this object were not found in the Framework section where one would expect to find them.

Content is available under Joomla! EDL unless otherwise noted.Joomla!® is a registered trademark of Open Source Matters, Inc.If you are experiencing technical issues with this website, please report it.
Notice a content problem? Create an account and fix it.