Request
On this page:
Questions answered by this recipe
- How do I pass parameters from one page to another, without using includes?
- How do I let readers select some or all of the page's content or styling?
- How do I show help or debug information via a request in the URL?
Description
This script provides markup to test the value of any parameter in the URL.
After activating this recipe you can use (:if request parameter value:)
to test whether the URL contains ?parameter=value
. You can also test whether the parameter has any value at all (as opposed to a particular value) by using (:if request parameter:)
Activation
To activate this recipe, download request.phpΔ, and put it in your cookbook directory. Add the following line to your local/config.php:
include_once("$FarmD/cookbook/request.php");
Usage
Syntax
- To test whether the URL contains a parameter:
(:if request
parameter:)
- To test whether the URL contains a parameter with a specific value:
(:if request
parameter value:)
For example:
(:if request from:)
tests whether the "from" parameter has a value in the URL.(:if request help subject1:)
tests whether "?help=subject1" is in the URL.
If the parameter has no value (that is, "?parameter="), it is treated as if it were not present.
Example of allowing multiple requests
Use the following markup:
Select part [[{*$FullName}part=one|1]] , [[{*$FullName}?part=two|2]], [[{*$FullName}?part=three|3]], or [[{*$FullName}?part=All|All]] (:if ( request part All ) or ( request part one ) or ( !request part ) :) You are viewing part 1 (:if ( request part All ) or ( request part two ) :) You are viewing part 2 (:if ( request part All ) or ( request part three ) :) You are viewing part 3 (:ifend:)
Example of showing debug information
You have page MyPage with the following on it:
(:if request debug 1:) This is line 1 (:ifend:) (:if request debug 2:) This is line 2 (:ifend:)
- Normally you will see nothing
- If you put in the URL
?debug=2
you will see "This is line 2".
Example of allowing a styling request
Use the following markup:
(:if request bold:)(:div1 style="font-weight: bold;":)(:ifend:) This is shown as bold only if requested. (:if request bold:)(:div1end:)(:ifend:)
- If you put in the URL
?bold=1
the text will be bold; if you specify?bold=
or omit the parameter, it's shown normally
Example of using the values entered on a form
You have page MyPage with the following on it
(:input form method=get:) (:input hidden n {*$FullName} :) (:input hidden submitted 1:) (:input default request=1:) Color: (:input checkbox red 1:) Red (:input checkbox blue 1:) Blue (:input checkbox green 1:) Green Background: (:input radio background yellow:) yellow (:input radio background "":) normal Rating of recipe: (:input select rating useful:) (:input select rating useless:) (:input submit:) (:input end:) (:if1 request submitted:)(:comment --- use the entered values if the form's submit button was pressed ---:) >>frame bgcolor={$?background}<< (:if request rating useful:) I'm glad you found this recipe useful. Please [[http://www.pmwiki.org/wiki/Cookbook/Request-Users?action=edit|add yourself as a user]]. (:else:) Sorry you found this recipe useless. (:ifend:) (:if2 ( request red ) or ( request blue ) or ( request green ) or ( request background ) :) You selected: (:if request red:) %red%red%% (:if request blue:) %blue%blue%% (:if request green:) %green%green%% (:if request background yellow:) with a yellow background. (:ifend:) (:else2:) You didn't select any colors! (:if2end:) (:if1end:)
Tips
For other ways to use URL requests, see Cookbook:HttpVariables.
Notes
Release notes
- 2015-08-11: Fixed comments
See also
Contributors
Comments
User notes +1: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.