1

I have defined layer with filtering. I've used operator IN because I have list of values:

LAYER
  NAME "loc_mistnosti3"
  TYPE POLYGON
  ...
  FILTERITEM 'ID'
  FILTER ( [ID] IN %id% )
  VALIDATION
     "id" "[0-9]"
  END

URL address contains this list of values:

...layer=loc_mistnosti3&**id=180,214**&map_size...

but result is still:

msCGILoadForm(): Web application error. Parameter 'id' value fails to validate.

Where is the problem?

3
  • Don't you need to URLEncode the commas within the list?
    – Vince
    Jun 10 '20 at 17:19
  • Because the value of id is 180,214 and your validatation pattern is [0-9]. There must be some fancy RegExp that accepts a list of numbers, separated by commas. Meanwhile you can validate anything with *.
    – user30184
    Jun 11 '20 at 0:30
  • I've tried possibly all but no success ... [0-9\,] - didn't work ... [*] - also didn't work. Answer is still msCGILoadForm(): Web application error. Parameter 'id' value fails to validate. msApplySubstitutions(): Regular expression error. Parameter pattern validation failed. or msCGILoadForm(): Web application error. Parameter 'id' value fails to validate. Jun 11 '20 at 11:13
2

BINGO!!!

So. My variable called id and it is the problem!

...&layer=loc_mistnostiT&id=212,213...

Definition of VALIDATION in LAYER looked like this:

  VALIDATION
   "id" "[0-9]"
  END

So I have looked into mapservutil.c and there is this:

    if(strcasecmp(mapserv->request->ParamNames[i],"id") == 0) {
     if(msEvalRegex(IDPATTERN, mapserv->request->ParamValues[i]) == MS_FALSE) {
       msSetError(MS_WEBERR, "Parameter 'id' value fails to validate.", 
       "msCGILoadForm()");
       return MS_FAILURE;
     }
     strlcpy(mapserv->Id, mapserv->request->ParamValues[i], IDSIZE);
     continue;
    }

It is answer which I got every time during my trying to solve my problem. And id in this code looked a bit suspiciously.

So I've changed my variable id to xid and everything is OK now!!!

My new definition is:

  VALIDATION
   "xid" "[0-9]"
  END

... and variable in URL is (id renamed to xid):

...&layer=loc_mistnostiT&xid=212,213...
2
  • So in summary, there were 2 issues regarding your original question: 1) your FILTER syntax was incorrect, and never would display your results, as I mentioned in my answer, you are missing the quotes such as FILTER ("[reg_code]" IN "%code%") and 2) you cannot use theid variable name, good catch, I've added this as a note at the bottom of mapserver.org/mapfile/validation.html
    – mapserving
    Jun 12 '20 at 11:56
  • And finally, for good karma and to help give back to the free software that you are relying on, please create a Pull Request to help improve the MapServer documentation, at github.com/mapserver/docs Thanks!
    – mapserving
    Jun 12 '20 at 12:06
2

I believe your FILTER syntax is incorrect. This is working for me (pay attention to the quotes in the FILTER) :

LAYER
  NAME "park"
  METADATA
    "wms_title"    "Parks"
  END
  DEBUG 5
  VALIDATION
    "code" "[0-9]"
  END    
  ..
  FILTER ("[reg_code]" IN "%code%")
  ...

END # Layer

You can test this outside the browser, at the commandline, such as:

mapserv -nh "QUERY_STRING=map=D:\ms4w\apps\stackexchange\filter-validation-364540\filter-validation.map&mode=map&layers=all&code=12,13" > ttt.png

Here is my parks layer in QGIS:

enter image description here

And here it is live on the MS4W demo server for you to try (try changing the end of the url to "code" values such as 24,12,13,0): https://ms4w.dev/cgi-bin/mapserv.exe?map=C:\ms4w\apps\stackexchange\filter-validation-364540\filter-validation.map&mode=map&layers=all&code=12,13 (MapServer 7.6)

Hope that helps.

(by the way, I just now added this commandline trick to the MapServer docs at https://mapserver.org/mapfile/validation.html )

-jeff

2
  • It looks simply. I've checked and updated my definition of localization layer according to your definition - no succes. If I put only one value 212 into variable id in URL so everything is OK - map is generated. If I put two values 212,213 so result is msCGILoadForm(): Web application error. Parameter 'id' value fails to validate.. It looks like some problem with separator. Jun 12 '20 at 6:13
  • I've tried crazy thing ... I've put values directly into layer definition into FILTER - here is my definition FILTER ("[ID]" IN "212,213") and it's OK - it works and map is generated with two highlighted areas! So It has to be problem with value separator during validation process. Jun 12 '20 at 6:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.