Quantcast
Channel:
Viewing all articles
Browse latest Browse all 4235

Re: I'm working on a licence key module

$
0
0

update, I now have this code which I'm almost certain produces the array I am looking for. However in the browser where the licence key field is outputted I have a blank page.

<?php

class LicenseKeyField extends TextField{

function validate($validator){

if(!empty ($this->value)){

// get dataobject and convert to array for licencekeys
public function getKeys(){
$sqlQuery = new SQLQuery();
$sqlQuery->setFrom('LicenceKeys');
$sqlQuery->addWhere('ProductDownloadID = ' . $this->ID);
$result = $sqlQuery->execute();
// Iterate over results
$keys = new ArrayList();
foreach($result as $row) {
$arrayData = new ArrayData(array(
'LicenceKeys' => $row['LicenceKeys']
)
);
$keys->add($arrayData);
}
return $keys;
}

// get licence key field value
$val = $this->value();

// 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;
}
}
}
}


Posted to: I'm working on a licence key module | Show Thread | Post Reply


Viewing all articles
Browse latest Browse all 4235

Trending Articles