AuxSelect

Summary: Dropdown widget that persists its selected value between pages
Version: 1.1.0
Prerequisites: PmWiki 2.2.0-beta27
Status: Stable
Maintainer: Marc Cooper -> mailto:gmane [snail] auxbuss [period] com
Discussion: AuxSelect-Talk
Categories:

Questions answered by this recipe

How do I allow a casual browser to make a selection on my site that persists from page to page?

How do I allow my site visitors to select their currency, so that I can display prices in that currency?

Description

This recipe allows you to create a dropdown form that is populated with values from a PHP array. The dropdown can be preceded by a text value. The current value is set by the site visitor via a button; a default value can be set by the admin. The current value is stored in a session variable.

To install

  1. Download auxselect.phpΔ
  2. Add the following to your config.php
      include_once("$FarmD/cookbook/auxselect.php"); 
    

To use

  1. Add an array of values for the dropdown to the array $AuxSelectData. For example,
      $AuxSelectData['currencies'] = array('EUR','GBP','USD'); 
    
  2. Use the following markup to display the dropdown, its option text label, and its button.
      (:auxSelect name arrayname [default] [text] [submittext] [id]:) 
    
    where
    • name is mandatory and is used for the name of the session variable used by this recipe
    • arrayname is mandatory and identifies the entry in $AuxSelectData that is used to populate the dropdown
    • default is the value of the item in the dropdown that the admin wishes to be preselected. The default is to select the first value in arrayname.
    • text can be used as a text label for the dropdown. The default is an empty string.
    • submittext is the button text. It defaults to 'set'.
    • id is the CSS id applied to the dropdown's <FORM>. The default value is auxselect. Note that the PmWiki's classes .inputbox and .inputbutton are available within this id to further format the widget.
Example:
  (:auxSelect currency currencies default=GBP text='Currency: '
                submittext='set' id=changecurrency:)

Additional features

AuxSelectData

You can populate an AuxSelect array via markup:

  (:auxselectdata arrayname [value1 [value2 ...]] :) 

e.g.

  (:auxselectdata somearray fred barney 'dino dog':) 

and immediately use it:

  (:auxselect test somearray text='Somearray: ':) 

auxselectdata has limited use on a single page -- although the selection will persist should recipe authors wish to use the value elsewhere -- but it can be used in group and site headers with more effect.

For security reasons, you cannot overwrite an array with auxselectdata that has already been defined.

Notes

To use the selected value within conditional markup, you can exploit the HttpVariables recipe, thus:

  
  (:auxSelect currency currencies default=GBP text='Currency: ':)

  (:if equal {$~currency} 'EUR':)fred(:if:)
  (:if equal {$~currency} 'GBP':)barney(:if:)
  (:if equal {$~currency} 'USD':)dino(:if:) 

Note that a dropdown can be applied site-wide via the skin within its .tmpl file via something like

    <div style='float:right;'>
    <!--markup:(:auxSelect currency currencies 
                           default=GBP text='Currency: ' -->
    </div>

You can display a session variable on a page via the HttpVariables recipe. For example:

    {$~currency}

Release Notes

  • v1.1.0 26/01/2007 Added AuxSelectData and allowed spaces in values
  • v1.0.0 25/01/2007 Initial release

See Also

Contributors

Marc Cooper -> mailto:gmane [snail] auxbuss [period] com

Comments

See discussion at AuxSelect-Talk

User notes? : 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.