Request

Summary: Extends conditional markup to test parameters in the URL, to allow pages to pass parameters via their URL links
Version: 2010-05-12
Prerequisites: Tested using Pmwiki version 2.10
Status: Beta
Maintainer: RandyB
License: GPL2
Users: +1 (View / Edit)
Categories: Markup PHP55
Download: request.phpΔ

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:)
Result: The user will see links to select parts 1, 2, 3, or All. Clicking on a link shows the requested part(s).

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:)
Result:
  • 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:)
Result:
  • 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:)
Result: The page that the form goes to after submission (in this case the same page) uses the values that the user entered on the form.

Tips

For other ways to use URL requests, see Cookbook:HttpVariables.

Notes

Release notes

  • 2015-08-11: Fixed comments

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".

See also

Contributors

Comments

This space is for User-contributed commentary and notes. Please include your name and a date (eg 2007-05-19) along with your comment. Optional alternative: create a new page with a name like "ThisRecipe-Talk" (e.g. PmCalendar-Talk).

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.