verify if an email already exists in newsletter table
This commit is contained in:
@@ -23,9 +23,12 @@
|
|||||||
|
|
||||||
namespace Thelia\Form;
|
namespace Thelia\Form;
|
||||||
|
|
||||||
|
use Symfony\Component\Validator\Constraints\Callback;
|
||||||
use Symfony\Component\Validator\Constraints\Email;
|
use Symfony\Component\Validator\Constraints\Email;
|
||||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||||
|
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||||
use Thelia\Core\Translation\Translator;
|
use Thelia\Core\Translation\Translator;
|
||||||
|
use Thelia\Model\NewsletterQuery;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,7 +65,13 @@ class NewsletterForm extends BaseForm
|
|||||||
->add('email', 'email', array(
|
->add('email', 'email', array(
|
||||||
'constraints' => array(
|
'constraints' => array(
|
||||||
new NotBlank(),
|
new NotBlank(),
|
||||||
new Email()
|
new Email(),
|
||||||
|
new Callback(array(
|
||||||
|
"methods" => array(
|
||||||
|
array($this,
|
||||||
|
"verifyExistingEmail")
|
||||||
|
)
|
||||||
|
))
|
||||||
),
|
),
|
||||||
'label' => Translator::getInstance()->trans('email'),
|
'label' => Translator::getInstance()->trans('email'),
|
||||||
'label_attr' => array(
|
'label_attr' => array(
|
||||||
@@ -71,6 +80,14 @@ class NewsletterForm extends BaseForm
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function verifyExistingEmail($value, ExecutionContextInterface $context)
|
||||||
|
{
|
||||||
|
$customer = NewsletterQuery::create()->findOneByEmail($value);
|
||||||
|
if ($customer) {
|
||||||
|
$context->addViolation("This email already exists");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string the name of you form. This name must be unique
|
* @return string the name of you form. This name must be unique
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user