Hi there,
I'm working on a simple licence key module which I think could be useful. However I am a little stuck on one thing.
In the below example there is a hardcoded array '$numbers' which holds some example licence keys. What I am trying to do is populate this with a dataobject, simple right? Well the hard part seems to be retrieving that dataobject and putting it into an array. I'm a bit confused as there seems to be a fair bit out there about how you can do this but as yet none of those methods have worked.
I'm wondering if anyone out there has any practical knowledge of converting dataobject results into arrays?
LicenseKeyField.php
<?php
class LicenseKeyField extends TextField{
function validate($validator){
if(!empty ($this->value)){
// get licence key field value
$val = $this->value();
$keys = array(
'AJCAOkwO',
'ANojxe4F',
'ARmsWx37',
'AfFBkUxU',
'AsQ2r9Fb',
'BDtvjcue',
'BWwCTj5V',
'BnZcCYJR'
);
// check the license key against a given pattern.
$patterns_flattened = implode('|', $keys);
if ( preg_match('/'. $patterns_flattened .'/', $val, $matches) ){
// matched
} else {
$validator->validationError(
$this->name,
"Sorry, you have not entered a valid code",
"validation",
false
);
return false;
}
}
}
}
Regards