PostSwitch StackDisplay content based on arguments passed from a form, or in the page address, or in php code.
The PostSwitch Stack lets you control the content of your page based on arguments passed in the page URL address (eg: …/index.php?product=1), or from a form submission, or based on internal PHP variables from code elsewhere on the page. So you can easily create a page for products, contacts, photos, etc. and show just the one(s) you want, or respond appropriately to form submissions by testing form field values, etc. Tons of ways to use this creatively - take a look at the LinkList Stack for examples as well, and use the PostDebug Stack for debugging!
How does it work?
The argument passed in the URL, or from the form is decoded and used to display, or hide, specific Stacks.
Use PostSwitch Stack options to choose the argument you wish to look for, from those found in the URL address (GET) or from those passed by a form submission (POST) or by looking at internal PHP variables set elsewhere on your page code. Sounds complicated but it’s really not! And, you can look for the existence of the variable, or an exact value, or any one of several values.
|Argument name||Enter the name of the argument to look for: in $_GET (index.php?arg=value in the URL), or $_POST (usually a field from a form submission) or an internal PHP variable ($something used in PHP on this page), in that order. This should not be left blank. This stack creates a PHP variable with this Argument name, and on a successful match to the optional value, a PHP variable named confirmSwitch (or variable named below) is set to true.|
|Argument values||Optional argument value(s) to check for. Enter one string, or several separated by comma and/or space; a match is achieved when the Argument named above exactly equals ANY ONE OR MORE of the values. Leave this blank to check only for the presence of the argument, or whether the PHP variable is defined. Any PHP variable value type such as string, float, int, or boolean true/false will work.|
|1. Check GET in URL?||Look for the Argument name in $_GET (index.php?arg=value in the URL).|
|2. Check POST from Form?||Look for the Argument name in $_POST (usually a field name from a form submission).|
|3. Check PHP Variable?||Look for the Argument name as a PHP variable ($something defined previously in the PHP of this page).|
|Extra edit info?||Enable extra information info in the RapidWeaver edit window.|
|Show true stack||Show an area for stacks to display when the var is found and optionally has the correct value. This is the if part of the conditional.|
|Show false stack||Show an area for stacks to display when the var is not found or the value is incorrect. This is the else part of the conditional.|
|Anchor name||Enter a unique name for an anchor to create inside this Stack to jump to using #anchor at the end of a URL. This is useful for ensuring this Stack scrolls into view when the page is loaded. This is optional and may be left blank if anchors are not needed.|
|Set PHP flag||On a successful match, the stack sets the PHP variable $confirmSwitch to true. If there is no match then the variable is not set or unset, it is left as-is. If this field is not blank, then it will be used as the name of this variable instead of confirmSwitch, which may be useful when multiple PostSwitch Stacks are used on the same page, and their results need to be tested individually elsewhere. The stack also sets a $variable named using Argument name, so you can test its actual value.|
Check out a examples of PostSwitch …
Example 1: a basic list of buttons are used in this example, each one linking back to this very page with product=1,2,3,4 parameters in the URL (hover the mouse to see). Click each Try button to see the content that the PostSwitch Stack displays. The content displayed is entirely up to you, and could be images, product information, text, etc.
Example 2: a simple form (in an HTML Stack) that calls this same page, and the field named “fruit” is used by PostSwitch to display content. Select an option and click Submit …
Choose an option and Submit then scroll back down to see the PostSwitch Stack in action!