MapServer allows certain elements of the map file to be altered at runtime by passing in variables on the URL. This only applies when MapServer is running as a CGI application, and is documented here: http://mapserver.org/cgi/runsub.html. We use this to allow client-side filtering in applications such as our Web Map Toolkit, for example passing in a URL parameter that is used in a FILTER on a LAYER, or in an EXPRESSION in a CLASS.
When used in either of these ways, the calling application may want to clear the filter entirely, i.e. supply no value at runtime. To avoid this returning no data, or breaking the map completely, MapServer permits setting default values for the variables as documented here: Default values if not provided in the URL. However, we have found this simply does not work as stated (using MapServer 6.01 anyway). We have tried setting the default value in a VALIDATION block positioned in the WEB section or in a LAYER, and while the pattern validation works in both cases, the default value does not.
Here’s a hypothetical example of what does not work for us (using a variable “year”):
VALIDATION
'year' '^[0-9]{4}$'
'default_year' '2014'
END
And here’s what we find does work, moving the settings into the METADATA section of the layer:
LAYER
…
METADATA
… other stuff…
'year_validation_pattern' '^[0-9]{4}$'
'default_year' '2014'
END
When I get time I need to check this on a more up-to-date version of MapServer, because I see this in the migration documentation for version 6.4: “Validation patterns cannot be specified in metadata blocks (i.e. using xxx_validation_pattern and default_xxx metadata entries), use VALIDATION blocks”.
This did make me wonder whether 6.0 was never intended to work with the default values inside VALIDATION blocks, but a trawl of the MapServer 6.0 documentation shows that it was. Let’s hope they’ve fixed it!