Page 1 of 1

form with a random number field?

Posted: 2013-09-23 08:23
by antonio
Hi all,
I need to create a form that should collect user data along with a random number.
The random number should be unique.
Sample form:
- name
- email
- random number (hidden field)

What is the best way to do this with ADDT or Kollection pro?

Another option could be:
- I creare two db tables: user_data and random_numbers (the latter could be pre-filled: I think 10.000 records should be enough).
- the "random_numbers" table should contains at least 3 fields: ID_num, number_num, status_num (1 or 0; 1=used, 0=not used).
- when I make the insert transaction in the user_data table I pick-up the next record from the "random_numbers" table;
- after inserting the record in the user_data table I should update the random_numbers table and change the picked-up record status to 1
This is what I think is best to do, but I don't know how to do it with ADDT.

I can easily create the custom transaction, but how can I link another transaction to pick-up from the random_numbers table and update that table accordingly?

I thank you very much in advance for any help.

Ciao ;).

tony

Re: form with a random number field?

Posted: 2013-09-23 09:35
by antonio
Hi all,
Alternatively, is there a way use the user registration wizard and generate the password automatically?
I tried creating a new registration page with the password field hidden but this doesn't work (I get null passwords).

TIA

tony

Re: form with a random number field?

Posted: 2013-09-23 22:06
by Fred
Hi Tony,
Creating a random number is easy enough, making sure it is unique is something totally different.
You either need to make the number long enough (that is unpractical for passwords and still no guarantee) or check the records in the database.
Having said that, passwords do not have to be unique, just hard to crack...

Here is a good example of a string generator

Code: Select all

<?php
function randStrGen($len){
$result = "";
    $chars = "abcdefghijklmnopqrstuvwxyz$_?!-0123456789";
    $charArray = str_split($chars);
    for($i = 0; $i < $len; $i++){
   $randItem = array_rand($charArray);
   $result .= "".$charArray[$randItem];
    }
    return $result;
}
?>
<?php
// Usage example
$randstr = randStrGen(15);
echo $randstr;
?>

Re: form with a random number field?

Posted: 2013-09-24 08:02
by antonio
Hi Fred, thanks for your reply.
I have a form that a user fills and once submitted he should receive an email with a random code (alphanumeric or numeric, but simple enough to read).
The random code must be unique.
It's not about security here; I just want to make sure a user can't find another code by calculating it.
What about 2 tables: users and codes?
In the codes table I would insert 10.000+ records with prefilled codes.
Once the user fill his form a new code is picked-up.
Then I need to update the codes table to make sure I don't pick-up an already picked-up number.
What do you think? Can I do this with ADDT?

TIA for any insight.

tony

Re: form with a random number field?

Posted: 2013-09-24 10:20
by Fred
Hi Tony,
Having a prefilled table will work but it defeats the object of doing things dynamically.
I hate doing the work thats why I have a pc/server.

So here is another solution to generate something unique

You should have something unique to identify the user when they log in. Yea?

Code: Select all

<?php
    $email = 'someone@emailaddress.com'; // Already unique
    $name = 'Name'; // Just for the hell of it
    $surname = 'Surname'; // Just for the hell of it
    $str = $email.$name.$surname;
    $md5str = md5($str,false);
    //echo $md5str;
?>
That should give you a nice unique random string

Re: form with a random number field?

Posted: 2013-09-24 10:42
by antonio
Fred wrote:Hi Tony,
Having a prefilled table will work but it defeats the object of doing things dynamically.
I hate doing the work thats why I have a pc/server.

So here is another solution to generate something unique

You should have something unique to identify the user when they log in. Yea?

Code: Select all

<?php
    $email = 'someone@emailaddress.com'; // Already unique
    $name = 'Name'; // Just for the hell of it
    $surname = 'Surname'; // Just for the hell of it
    $str = $email.$name.$surname;
    $md5str = md5($str,false);
    //echo $md5str;
?>
That should give you a nice unique random string
I agree with you. But you know: when you are near a dead line and you are not a programmer as you are... ;)
Your approch is really interessting and I could easily add it to the form.
But the code generated by MD5 is too long for an end-user that have to type it exactly somewhere else.

I just created 2 transaction and linked them.
Transaction 1: insert the record in the user table getting the first unused record from the codes table (1.000.000 records)
Transaction 2: update the codes table by setting a specific field to the ID of transaction 1 (this way I know where used codes have been used)

It seems to work. Yes it's not so dynamic, but I can live with it.

Thanks anyway for your precious help, Fred. ;)

Tony

Re: form with a random number field?

Posted: 2013-09-24 12:46
by Fred
No it is actually quite simple
Just before the send mail trigger or insert trigger you add something similar to this to get the info and add it to the database and email.

http://www.interaktonline.info/article/ ... email.html