I would like to check if an e-mail address does not allready exists in the database before adding the new record. So, it must be unique.
I allready have some other validation in my schema, but for this I guess I need to do some PHP validation?
This is what I have done so far:
<?php
$validator = $subscriber->getValidator();
/* save */
if ($validator == false || $subscriber->save() == false) {
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
$messages = $validator->getMessages();
foreach ($messages as $errorMsg) {
$o .= $errorMsg['message'].'<br />';
}
$this->modx->smarty->assign('errors', $o);
$this->modx->smarty->assign('name', $_POST['name']);
$this->modx->smarty->assign('email', $_POST['email']);
$this->modx->smarty->assign('active', $_POST['active']);
}
return $this->modx->smarty->fetch($this->config['basePath'].'templates/add_subscriber.html');
}
else
{
return $this->listSubscribers(); //terug naar overzicht
}
?>
How to extend the validation, so that it only accepts new e-mailadresses?