RE: [PEAR] QF: Group validation max 1 value
| From: | Daniel Kopp | Date: | Sat, 01 Nov 2003 16:56:06 +0000 |
| Subject: | RE: [PEAR] QF: Group validation max 1 value | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-8707@lists.php.net to get a copy of this message | ||
Hi!
Just in case someone else is in need of something like this:
Here is my solution:
$this->registerRule('checkmax', 'function', 'checkMax');
$this->addRule('anredegroup',
'please either enter a new value or choose one - not
both',
'checkmax', 1);
The function:
function checkMax($elementName, $array, $max)
{
$count=0;
foreach ($array as $key=>$value)
if ($value!='') // if you want - you may add brackets :-)
$count++; // as many as you like - they are free
if ($count>$max)
return false;
else
return true;
}
So - where a normal validation function gets a simple variable - a group
validation function gets an array with the values ... Just for those who -
like me - did not just assume that :-)
BTW: what is "elementName" for?
Regards
Daniel
> -----Original Message-----
> From: Daniel Kopp [mailto:pear@daniu.de]
> Sent: Tuesday, October 28, 2003 10:19 PM
> To: pear-general@lists.php.net
> Subject: [PEAR] QF: Group validation max 1 value
>
>
> Hi!
>
> How can I validate a Group to have max. 1 value set? The
> manual shows how to get min. 1
>
> I need that for a special field: in Databases I would like to
> have a select box followed by a text-field - like this:
>
> <Select a value> or set a <new> value
>
> The Selectbox keeps all the values in the Database (Select
> Distinct ...) and with <new> the user can set a custom value
> which will become a DB-value next time (by that it is easier
> to avoid different values that are actually same). For that
> reason I need a max 1 value group rule. Maybe someone could
> also invent a standard QF-field like that? If I would be more
> in QF I would do it ...