adi_gps – Extract GET & POST variables

This plugin extracts GET/POST variables from the URL and assigns them to TXP variables.

Attributes

name="var name"

- a single GET/POST variable to extract. Default = “” (extract all GET variables). See post attribute for extracting POST variables.

new="var name"

- rename the variable. Default = “” (no rename). Only applies when retrieving a single GET/POST variable.

txpvar="boolean"

- duplicate the GET/POST variable as a TXP variable of the same name. Default = “1” (Yes). Requires Textpattern 4.0.7. Switch off if using versions prior to this.

post="boolean"

- extract POST variables as well. Default = “0” (No). Only applies in “extract all” mode.

quiet="boolean"

- don’t display variable value. Default = “0” (display variable value). Only applies when retrieving a single GET/POST variable. Quiet mode automatically switched on with “extract all” mode.

global="boolean"

- make the variable global in scope. Default = “1” (Yes).

escape="mode"

- escape HTML entities in variable value. Default = “” (no escape). Use escape="html" to switch on.

decode="boolean"

- decodes any remaining %## encoding in the variable values. Default = “0” (No). Not normally required but may be needed if URL has been processed by htaccess.

list="boolean"

- outputs a list of the extracted variables & their values. Handy for debugging. Default = “0” (No list).

Examples

<txp:adi_gps />

- extract all GET variables and duplicate them as TXP variables.

<txp:adi_gps post="1" />

- extract all GET and POST variables and duplicate them as TXP variables.

<txp:adi_gps name="myvar1" />

- extract a variable called myvar1 from URL, create a TXP variable of the same name and display it’s value.

<txp:adi_gps name="myvar2" txpvar="0" />

- extract a variable called myvar2 from URL and display it’s value. No TXP variable is created (suitable for use with Textpattern versions prior to 4.0.7).

<txp:adi_gps name="myvar3" quiet="1" />

- extract a variable called myvar3 from URL, create a TXP variable of the same name but don’t display it’s value.

Using the URL variables in pages or forms

Because, by default, adi_gps duplicates the extracted URL variables as TXP variables you can use all the standard TXP variable tags to process them:

  • <txp:variable />
  • <txp:if_variable />

For example:

<txp:adi_gps name="myvar" quiet="1" />
<txp:if_variable name="myvar" value="some_value">
... do something different ...
<txp:else />
... the same old thing ...
</txp:if_variable>

Using URL variables in articles

You can also use <txp:adi_gps /> within articles. For example:

The value of myvar is <txp:adi_gps name="myvar" />

or if you’ve already extracted the variable elsewhere:

The value of myvar is <txp:variable name="myvar" />

No escaping from Textile is required (e.g. using notextile. or == ... ==).

Accessing the extracted GET/POST variables in PHP

By default, adi_gps makes extracted URL variables available in the global scope. For example if $myvar1, $myvar2 & $myvar3 have been extracted previously they can be accessed in PHP snippets as follows:

<txp:php>
global $myvar1,$myvar2,$myvar3;
echo "$myvar1 $myvar2 $myvar3";
</txp:php>

Version 0.1 - Download (Uncompressed) Support