Functions Dev: Difference between revisions
(Created page with "The following page describes some important functions used by dolibarr. GETPOST GETPOST() : function to retrieve the content of GET or POST variables in a more secure way. Th...") Tag: 2017 source edit |
m (→GETPOST) Tag: 2017 source edit |
||
| (13 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
{{TemplateDocDevEn}} | |||
The following page describes some important functions used by dolibarr. | The following page describes some important functions used by dolibarr. | ||
GETPOST() : function to retrieve the content of GET or POST variables in a more secure way. The PHP methods $_GET and $_POST should not be used. | ==GETPOST== | ||
GETPOST() : function to retrieve the content of GET or POST variables in a more secure way. | |||
The PHP methods $_GET and $_POST should not be used. | |||
Possible use : | Possible use : | ||
| Line 8: | Line 13: | ||
Example in php: | Example in php: | ||
$myField= $_POST["myField"]; | $myField= $_POST["myField"]; | ||
becomes if the element passed in parameter is a number : | becomes if the element passed in parameter is a number : | ||
$myField= GETPOST("myField", 'int'); | $myField= GETPOST("myField", 'int'); | ||
Possible parameters of the second argument : | |||
{| class="wikitable" | |||
|+ | |||
!Parameters | |||
! | |||
|- | |||
|'none' | |||
|for no parameter type check | |||
|- | |||
|'int' | |||
|check that it's a numeric (integer or decimal). Warning, for an amount or a rate, you must use alpha to accept non decimal chars or thousand separators used by some countries. The data must be then converted with price2num(GETPOST('key', 'alpha')) | |||
|- | |||
|'intcomma' | |||
|checks that it is a list of ID separated with commas ('1,8,123,99,...') | |||
|- | |||
|'alpha' | |||
|same than 'alphanohtml' (kept for backward compatibility) | |||
|- | |||
|'aZ' | |||
|verifies that it is a-z only | |||
|- | |||
|'aZ09' | |||
|verifies that it is non-special characters and numbers | |||
|- | |||
|'array' | |||
|verifies that it is an array | |||
|- | |||
|'san_alpha' | |||
|purged string (do not use for free text) | |||
|- | |||
|'nohtml' | |||
|verifies that there is no html code | |||
|- | |||
|'alphanohtml' | |||
|checks that the data is a non dangerous string with no html code inside. | |||
|- | |||
|'restricthtml' | |||
|must be used for any data entered by users to enter a html content | |||
|- | |||
|'custom' | |||
|defined by the following filters and options with the parameters $filter and $options | |||
|} | |||
For more information see the comments of the function in the file htdocs/core/lib/functions.lib.php | For more information see the comments of the function in the file htdocs/core/lib/functions.lib.php | ||
GETPOSTISSET() | |||
==GETPOSTISSET()== | |||
GETPOSTISSET(variableName) allows to know if the GET or POST variable passed in parameter is defined. | GETPOSTISSET(variableName) allows to know if the GET or POST variable passed in parameter is defined. | ||
| Line 35: | Line 73: | ||
Example in php: | Example in php: | ||
if (isset($_POST['myField'])){...} | if (isset($_POST['myField'])){...} | ||
becomes : | becomes : | ||
if (GETPOSTISSET('myField')){...} | if (GETPOSTISSET('myField')){...} | ||
For more information see the comments of the function in the file htdocs/core/lib/functions.lib.php | For more information see the comments of the function in the file htdocs/core/lib/functions.lib.php | ||
img_picto | |||
==img_picto== | |||
img_picto() function to insert an image. | img_picto() function to insert an image. | ||
| Line 49: | Line 88: | ||
For more information see the comments of the function in the file htdocs/core/lib/functions.lib.php | For more information see the comments of the function in the file htdocs/core/lib/functions.lib.php | ||
Latest revision as of 15:05, 1 April 2021
The following page describes some important functions used by dolibarr.
GETPOST
GETPOST() : function to retrieve the content of GET or POST variables in a more secure way. The PHP methods $_GET and $_POST should not be used.
Possible use :
Example in php:
$myField= $_POST["myField"];
becomes if the element passed in parameter is a number :
$myField= GETPOST("myField", 'int');
Possible parameters of the second argument :
| Parameters | |
|---|---|
| 'none' | for no parameter type check |
| 'int' | check that it's a numeric (integer or decimal). Warning, for an amount or a rate, you must use alpha to accept non decimal chars or thousand separators used by some countries. The data must be then converted with price2num(GETPOST('key', 'alpha')) |
| 'intcomma' | checks that it is a list of ID separated with commas ('1,8,123,99,...') |
| 'alpha' | same than 'alphanohtml' (kept for backward compatibility) |
| 'aZ' | verifies that it is a-z only |
| 'aZ09' | verifies that it is non-special characters and numbers |
| 'array' | verifies that it is an array |
| 'san_alpha' | purged string (do not use for free text) |
| 'nohtml' | verifies that there is no html code |
| 'alphanohtml' | checks that the data is a non dangerous string with no html code inside. |
| 'restricthtml' | must be used for any data entered by users to enter a html content |
| 'custom' | defined by the following filters and options with the parameters $filter and $options |
For more information see the comments of the function in the file htdocs/core/lib/functions.lib.php
GETPOSTISSET()
GETPOSTISSET(variableName) allows to know if the GET or POST variable passed in parameter is defined.
Example in php:
if (isset($_POST['myField'])){...}
becomes :
if (GETPOSTISSET('myField')){...}
For more information see the comments of the function in the file htdocs/core/lib/functions.lib.php
img_picto
img_picto() function to insert an image.
print img_picto(imagetitle,imagename);
For more information see the comments of the function in the file htdocs/core/lib/functions.lib.php