[Solved] Manage the uniqueness of a random string automatically

georgie

Member
Hello

I want to generate a random string of 14 characters automatically during a form submission.
OK, I do this with success, in a Default value (Eval) on a simple field:
Code:
return substr(str_shuffle(str_repeat('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', mt_rand(1,14))),1,14);

But I want to be sure of the uniqueness of my string. So I can not just use isunique plugin, because I would do this automaticallyand hidden.
Is it possible in Eval?

Thank you

Georges
 
Thank, I tried, but I have always the message 'Something went wrong!', even deleting 'these 3 lines':
Code:
if ($oops++ > 10) {
      return "Something went wrong!";
   }

Also my SQL system seems to want:
Code:
->where('my_field LIKE '

Instead of:
Code:
->where('my_field= '

This is not a problem, but I do not understand why it returns a error.

Georges
 
Can you post your complete code?
The same error message is generated in the exception (so better use two different messages).
 
Can you dump the query (when it's using the =) ...

var_dump((string)$myQuery);exit;

... just after the setQuery(), and see if there's some obvious problem with it? I can't see anything in my original code that would cause a problem.

If you can't see the problem, paste it here.

-- hugh
 
Hey! Yes thank you, dumping and testing the query, I understand:
My problem was not linked to the "=" or other syntax, but about the name of my random field.

Indeed I would do this to customize the Acymailing subscribe form myself. The field "key".

But this name seems to be a key word in MySQL, so just adding the table name, it works:

->where('#_acymailing_subscriber.key = ' . $myDb->quote($myString));

THX
 
Yeah, it's always best to use $myDb->quoteName('your_field_name') ...

Code:
->where($myDb->quoteName('key') . ' = ' . $myDb->quote($myString));

... or you can include the table name .... $myDb->nameQuote('your_table_name.your_field_name').

I have a bad habit of not doing that, although I pretty much know what field names are key words and will need it.

-- hugh
 
Perfect, thank you!I note, "quoteName", OK.

However, when discussing with the Acymailing support, it appears that the management of this field in Acymailing is useless when creating a new subscriber, and that the value of this field will be automatically created by the extension when necessary.
Which makes even easier to do what I want to do. I am going to modify my doc accordingly.

Thank you

Georges
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top