Added isset_param() convenience function to test if a param is set.

To get the nasty activity in one place and to improve code readability.
This commit is contained in:
thepurpleblob 2005-06-10 09:51:25 +00:00
parent 8ee1b0afab
commit 7a530277ef

View file

@ -171,6 +171,21 @@ function optional_param($varname, $default=NULL, $options=PARAM_CLEAN) {
return clean_param($param, $options); return clean_param($param, $options);
} }
/**
* Convenience function to test if a parameter is set
* @param string $varname name of the parameter
* @return boolean true if set otherwise false
*/
function isset_param($varname) {
if (isset($_GET[$varname])) {
return true;
}
if (isset($_POST[$varname])) {
return true;
}
return false;
}
/** /**
* Used by {@link optional_param()} and {@link required_param()} to * Used by {@link optional_param()} and {@link required_param()} to
* clean the variables and/or cast to specific types, based on * clean the variables and/or cast to specific types, based on
@ -415,13 +430,29 @@ function require_variable($var) {
function optional_variable(&$var, $default=0) { function optional_variable(&$var, $default=0) {
global $CFG; global $CFG;
if (!empty($CFG->disableglobalshack)) { if (!empty($CFG->disableglobalshack)) {
error( 'The optional_variable() function is deprecated.' ); error( "The optional_variable() function is deprecated ($var, $default)." );
} }
if (! isset($var)) { if (! isset($var)) {
$var = $default; $var = $default;
} }
} }
/**
* If a variable is empty set it to the default
* otherwise leave it alone
* @param mixed $var the variable to test
* @param mixed $default the default value
* @return boolean true if variable has changed
*/
function set_default( &$var, $default ) {
if (empty($var)) {
$var = $default;
return true;
}
return false;
}
/** /**
* Set a key in global configuration * Set a key in global configuration
* *