[ic] [counter]

Kevin Walsh interchange-users@interchange.redhat.com
Thu Mar 28 21:19:01 2002


> 
> I've been reading up on the [counter] tag on the IC resource site.
> 
> I need a form to auto generate a random 3 digit numerical code and insert it
> into a database table.  I'd like the numbers to be very speratic such as
> "784" and the next one might be "239", etc.
> 
> More info on my appliation:
> 
> New customers will receive this "key" in their email to verify they entered
> a valid email address.  The last step of the signup process will ask them
> for this key.
> 
> Can someone provide an example using this tag?  I don't see anything in the
> archives relating to this topic.. thanks.
> 
The [counter] tag won't generate random numbers for you.

You could create a UserTag like this:

    UserTag generate_key Order length
    UserTag generate_key Routine <<EOR
    sub {
        my $length = shift || 1;
        my $out;

        $out .= int(rand(10)) for (1 .. $length);
        $out;
    }
    EOR

...and call it like this: [generate-key length=3]

Once you have the number, you can put it into the database table
in any way you see fit.

-- 
   _/   _/  _/_/_/_/  _/    _/  _/_/_/  _/    _/
  _/_/_/   _/_/      _/    _/    _/    _/_/  _/   K e v i n   W a l s h
 _/ _/    _/          _/ _/     _/    _/  _/_/    kevin@cursor.biz
_/   _/  _/_/_/_/      _/    _/_/_/  _/    _/