[pmwiki-users] New recipe: AuxSelect

marc gmane at auxbuss.com
Sat Jan 27 10:11:34 CST 2007


Martin Fick said...
> --- marc <gmane at auxbuss.com> wrote:
> > marc said...
> >
> > In more simple language: it's easy to create a
> > currency selector with this recipe. For example:
> > 
> > In config.php
> > 
> >   $AuxSelectData['currencies'] =
> > array('EUR','GBP','USD');
> > 
> > In page:
> > 
> >   (: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:)
> 
> It seems like it would be possible to implement more
> of this recipe with the httpvariables recipe using
> (untested):
> 
> (:session currencies[] EUR:)
> (:session currencies[] GBP:)
> (:session currencies[] USD:)

You can populate the array however you like. The example I gave is hard 
coded, kinda, but I also use a database

    $AuxSelectData['orders'] = $Member->getOrders();

 and session variables - I do this via an object, but this works:

    $AuxSelectData['somearray'] = $_SESSION['somearray'];

There's nothing to stop you using page text variables, or building the 
list dynamically in response to user actions.

> You may need to use indexes for that to work.  This
> leads me to the idea of adding a new shorthand to help
> set arrays with the httpvariables recipe making it
> even easier?  Maybe something like:
> 
> (:session currencies[] EUR GPB USD :)
> 
> Apply that to cookie assignment also.  What do you
> think?

I can see that populating the array via a page is useful - and I have 
thought about this - but the purpose of the recipe is to maintain state 
across pages. That means that populating the array via markup entails 
the populating markup being available to all of those pages and thus 
either replicated on each appropriate page, or placed in, say, group or 
site headers. I didn't have any need for such functionality, so I 
haven't added it. In any case, it can be added via local customisation, 
if needed.

Another way would be to create markup to populate a new entry for 
$AuxSelectData. (For security reasons, it wouldn't allow an existing 
entry to be overwritten.)

> Now, I think that your recipe could be implemented
> with just a bunch of select statements:
> 
> (:input default currency {$~currency}:)
> (:input select name=currency value={$~currencies[1]}:)
> (:input select name=currency value={$~currencies[2]}:)
> (:input select name=currency value={$~currencies[3]}:)

Although the selected state still needs to be stored.

Also, keep in mind, that you might have differing options for different 
users - as I do - so keeping the options dynamic is vital.

-- 
Cheers,
Marc




More information about the pmwiki-users mailing list