• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Unique code validation

Unique code validation 15 years 4 months ago #9231

  • rubenl
  • rubenl's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 13
Hi,

In this article (http://www.rsjoomla.com/customer-support/documentations/34-custom-scripting/85-unique-registration-number.html) is an instruction how to validate an unique code.

Is there a max in the script 'Script called on form process'? I would like to insert 75.500(!) unique codes. But when I insert them and save, the script is saved untill the 5952nd code, the other codes and the end of the script hasn't been saved...

Any sugfgestions?
The administrator has disabled public write access.

Re:Unique code validation 15 years 4 months ago #9260

  • bogdanc
  • bogdanc's Avatar
  • OFFLINE
  • Moderator
  • Posts: 669
  • Thank you received: 11
Hello,

There shouldn't be any limit in how much scripts you can add in the Scripts tabs. However, please take into account your server's security settings. If the information that's being added to the database (the script itself is saved in the database when you save the form) is larger than what your SQL server is allowed to process, this would produce unexpected results (either data being trimmed or not saved at all). Another thing to check for is PHP syntax errors.

But instead of adding the unique codes in the Scripts tab, you can add them into your database. Just create a table (using phpMyAdmin, let's call the table "jos_uniques") that would contain one column (let's call the column "number") that's a VARCHAR with 255 length. Now you will have to insert your codes in the database. After you do this, you can try this in the Scripts tab:

instead of:
$validCodes = array('AAAA','BBBB','CCCC','DDDD');

use:
$db = JFactory::getDBO();
$db->setQuery("SELECT `number` FROM #__uniques");
$validCodes = $db->loadResultArray();

This however will load all of the 75.500 unique codes in an array, which might be a bit too much, your server might run out of allowed memory. Here's another approach: instead of these lines:
$validCodes = array('AAAA','BBBB','CCCC','DDDD');
$foundValid = false;
foreach($validCodes as $validCode)
if( strtolower($validCode) == strtolower($_POST['form']['RegistrationCode'])) $foundValid = true;

use the following:
$db = JFactory::getDBO();
$db->setQuery("SELECT `number` FROM #__uniques WHERE `number`='".$db->getEscaped($_POST['form']['RegistrationCode'])."'");
$foundValid = $db->loadResult();
The administrator has disabled public write access.

Re:Unique code validation 9 years 4 months ago #33358

  • molotov
  • molotov's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 6
Hello,

While searching for a solution I found this forum entry.
I tried to integrate your code but couldn't get it to work. Could you maybe help me?
I'd like to have load an array of codes from a database table. I created the table XXX__uniques with the parameters that you were indicating and populated it with a few test codes.
Then I modified the code as you said but somehow the form always answers that the code is wrong, although it is a correct one.
I would be very grateful for any help.
Here is the code as I changed it using your indications.
public static function registrationCode($value, $extra = null, $data = null) {
  // Define an array of valid codes
    $db = JFactory::getDBO();
    $db->setQuery("SELECT `number` FROM #__uniques");
    $validCodes = $db->loadResultArray(); 
 
    foreach ($validCodes as $code) {
    // This makes both values lowercase, ie. the submitted value and our code.
    if (strtolower($value) == strtolower($code)) {
      // If they're a match, return true.
      return true;
    }
  }
 
  // When all of the above fails, the supplied code is incorrect, so we have to return false.
  return false;
}
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!