コード例 #1
0
 /**
  * @param Translator   $translator
  * @param UserValidator $userValidator
  */
 public function __construct(Translator $translator, UserValidator $userValidator)
 {
     parent::__construct('tasksForm');
     $userValidator->setUseAsBaseFieldset(true);
     $this->validationRules = ['csrf' => ['required', 'error_message' => $translator->translate('The form request has expired. You must resubmit the form in order to continue.')]];
     $this->setValidationGroup(['user' => ['profile' => ['fname', 'lname'], 'tasks'], 'csrf']);
     return $this->addElements([$userValidator, new Csrf('csrf')]);
 }
コード例 #2
0
 /**
  * @param Translator   $translator
  * @param UserValidator $userValidator
  */
 public function __construct(Translator $translator, UserValidator $userValidator)
 {
     parent::__construct('adminAccountForm');
     $that = $this;
     $userValidator->addValidationRule('email', ['name' => 'Callback', 'break_chain_on_failure' => true, 'options' => ['callback' => function ($value) use($that) {
         $count = User::where('email', $value);
         if ($that->getObject()->id) {
             $count = $count->where('id', '!=', $that->getObject()->id);
         }
         $count = $count->count();
         return !(bool) $count;
     }, 'message' => $translator->translate('The email already exists')]])->setUseAsBaseFieldset(true);
     $this->validationRules = ['csrf' => ['required', 'error_message' => $translator->translate('The form request has expired. You must resubmit the form in order to continue.')]];
     return $this->addElements([$userValidator, new Csrf('csrf')]);
 }