Pk19000 Pk19000 - 1 month ago 11
PHP Question

How can I check required_param is set or not in Moodle?

I wanna check

required_param('LType',PARAM_ALPHA)
is set or not? How can I do this?
I use this but it it doesn't work correctly:

if(!isset(required_param('LType',PARAM_ALPHA)))
{echo "salaam";exit;}

Answer

required_param means that the parameter must exist (or Moodle will throw an immediate, fatal error).

If the parameter is optional, then use optional_param('name of param', 'default value', PARAM_TEXT) instead. Then you can check to see if this has the 'default value' (I usually use null as the default value).

In either case, isset() does not make sense, as the variable always has a value assigned to it.