{qss:variable_name:delimiter}

Description

Returns a GET or POST parameter from the current request, HTML-encoded so it is safe to print into a page; cookies are never read. qss is the safe twin of qs: it runs the same lookup and then passes the result through safe(), the same encoder that turns less-than, greater-than, ampersand and quotes into HTML entities. Use qss every time you echo a value that came from the URL or a submitted form into HTML - it stops a crafted parameter from injecting markup or script (a cross-site scripting attack). Reach for the raw qs only when the value is consumed by another command rather than written straight to the page. With no parameter name qss returns the raw URL query string (everything after the ?, still URL-encoded; POST data is not included), html-encoded. Given a name it returns that one parameter; a name that is not present expands to an empty string. A name containing brackets, such as a form field array index, is looked up literally in the URL query string only. When the parameter is an array - a name sent with brackets, such as tag[]=red&tag[]=green - a second delimiter argument joins the values; without a delimiter the array is returned as JSON. A name repeated without brackets keeps only its last value. qss is recomputed on every request and its arguments are not whitespace-trimmed.

Parameters

variable_name optional default (empty - returns the whole query string)

Name of the GET or POST parameter to read, html-encoded on the way out; cookies are never read. Omit it to get the raw URL query string (everything after the ?, still URL-encoded; POST data is not included). A name that is not present in the request expands to an empty string. You may also pass a full bracketed field name (a form field array index); it is looked up literally in the URL query string only (not in POST data) and returned URL-decoded (+ stays +), html-encoded.

delimiter optional default (none - multiple values are returned as JSON)

Used only when the parameter is an array - a name sent with brackets, such as tag[]=red&tag[]=green. The values are joined with this string. If you leave it out, the array is returned as a JSON array instead of a joined string. A name repeated without brackets is not an array - PHP keeps only the last value. It has no effect on a single-value parameter.

Examples

test[{qss:surname}]
Expected[]
Actual[]
When the named parameter is not in the request, qss expands to an empty string. Here the page is rendered without a surname parameter, so the brackets show nothing between them. This is the deterministic side of qss; the cases below depend on what the visitor actually sent.
virtual<a href="/cz/review?id={qss:revize}">open</a>
Expected<a href="/cz/review?id=42">open</a> (for ?revize=42)
Actualopen
Echo a parameter into the href of a link. Because qss encodes the value, a parameter that tried to break out of the attribute is neutralised. For ?revize=42 the link points at /cz/review?id=42. This mirrors real toolkit views that pass the current selection on to the next page.
test{ifset:{qss:filter}:filtering on:no filter chosen}
Expectedno filter chosen
Actualno filter chosen
A common real pattern: branch on whether a parameter was supplied. ifset emits its first text when the value is non-empty, otherwise the fallback. Rendered here without a filter parameter, qss is empty, so ifset returns no filter chosen. With ?filter=news it would print filtering on.
virtual{qss:surname}
ExpectedHavel (for ?surname=Havel)
Returns the value of the surname parameter, html-encoded. For the URL ending in ?surname=Havel it prints Havel. This is the everyday use: safely echo a single value that came from the URL or a form.
virtual{qss:tag:, }
Expectedred, green, blue (for ?tag[]=red&tag[]=green&tag[]=blue)
When the parameter is sent as an array (a multi-select whose name ends in [], e.g. ?tag[]=red&tag[]=green&tag[]=blue), the second argument joins the values: comma-space gives red, green, blue. Without the delimiter the same input would come back as the JSON array of the three values. Repeating the name without brackets keeps only the last value.
virtual{ifeq:{qss:edit}:on:editing enabled:editing off}
Expectedediting enabled (for ?edit=on)
Actualediting off
Drive page state from a query parameter. For ?edit=on this prints editing enabled; any other value or no parameter prints editing off. A real toolkit view uses this idiom to toggle an in-place edit mode from a link.
virtual{qss}
Expectedsurname=Havel&amp;lang=cz (for ?surname=Havel&lang=cz)
With no parameter name qss returns the raw URL query string (everything after the ?, still URL-encoded), html-encoded; POST data is not included. Useful for debugging or for carrying the current parameters over into a link.
virtual{qss:surname}
Expected&lt;b&gt;bad&lt;/b&gt; (for ?surname=<b>bad</b>)
The point of qss over qs: the value is passed through safe(), so a parameter carrying markup comes out as harmless entities and cannot inject tags or script. For ?surname=<b>bad</b> qss prints the encoded text; qs would print the live tags. Always use qss when writing a parameter into HTML.