Author: (shea@silverstripe.com.au)
Inheritance: extends Validator
 private function Form()
 {
     $fields = FieldList::create(TextField::create('Title'), TextField::create('Subtitle'));
     $actions = FieldList::create(FormAction::create('submit', 'submit'));
     $validator = ZenValidator::create();
     return Form::create(Controller::curr(), 'Form', $fields, $actions, $validator);
 }
 /**
  * @return ZenValidator
  */
 public function getCMSValidator()
 {
     // create any validation contrain we need
     $validator = ZenValidator::create();
     foreach ($this->config()->get('validation') as $field => $validation) {
         // protection against misconfiguration: is this field actually shown? no? okay, don't validate.
         if (in_array($field, $this->config()->hideCMSInputs)) {
             // just required?
             if (array_key_exists('required', $validation)) {
                 $validator->setConstraint($field, Constraint_require::create()->setMessage('This field is required.'));
             }
             // min length?
             if (array_key_exists('minLength', $validation)) {
                 $validator->setConstraint($field, Constraint_length::create('min', $validation['minLength'])->setMessage(sprintf('Please enter at least %d characters.', $validation['minLength'])));
             }
             // max length?
             if (array_key_exists('maxLength', $validation)) {
                 $validator->setConstraint($field, Constraint_length::create('max', $validation['maxLength'])->setMessage(sprintf('Please enter maximal %d characters.', $validation['maxLength'])));
             }
             // width?
             if (array_key_exists('width', $validation)) {
                 $validator->setConstraint($field, Constraint_dimension::create('width', $validation['width'])->setMessage(sprintf('Please upload an image with an width of %s pixel.', $validation['width'])));
             }
             // height?
             if (array_key_exists('height', $validation)) {
                 $validator->setConstraint($field, Constraint_dimension::create('height', $validation['height'])->setMessage(sprintf('Please upload an image with an height of %s pixel.', $validation['height'])));
             }
         }
     }
     $this->extend('updateCMSValidator', $validator);
     return $validator;
 }
 private function Form()
 {
     $fields = FieldList::create(CheckboxField::create("IsTrue", 'Is it true?'), TextField::create("SN", "SN"), TextField::create("Name", "Name"));
     $actions = FieldList::create(FormAction::create('submit', 'submit'));
     $validator = ZenValidator::create();
     return Form::create(Controller::curr(), 'Form', $fields, $actions, $validator);
 }
 function __construct(Controller $controller, $name)
 {
     $this->currController = $controller;
     $fields = new FieldList(array(TextField::create("FirstName")->setTitle(_t("ContactPage.FIRSTNAME", "First Name"))->addPlaceholder(_t("ContactPage.FIRSTNAMEPLACEHOLDER", "Your First Name"))->setMaxLength(55)->setAttribute("autocomplete", "off"), TextField::create("LastName")->setTitle(_t("ContactPage.LASTNAME", "Last Name"))->addPlaceholder(_t("ContactPage.LASTNAMEPLACEHOLDER", "Your Last Name"))->setMaxLength(55)->setAttribute("autocomplete", "off"), EmailField::create("Email")->setTitle(_t("ContactPage.EMAIL", "Email"))->addPlaceholder(_t("ContactPage.EMAILPLACEHOLDER", "Your Email address"))->setMaxLength(55)->setAttribute("autocomplete", "off"), TextField::create("Phone")->setTitle(_t("ContactPage.PHONE", "Phone"))->addPlaceholder(_t("ContactPage.PHONEPLACEHOLDER", "Your Phone number"))->setMaxLength(55)->setAttribute("autocomplete", "off"), TextareaField::create("Description")->setTitle(_t("ContactPage.DESCRIPTION", "Message"))->addPlaceholder(_t("ContactPage.DESCRIPTIONPLACEHOLDER", "Your Message for us"))->setRows(6), TextField::create("Url")->setTitle("")->addPlaceholder(_t("ContactPage.URL", "Url"))->setMaxLength(55)->setAttribute("autocomplete", "off"), TextareaField::create("Comment")->setTitle("")->addPlaceholder(_t("ContactPage.COMMENT", "Comment"))->setRows(6), HiddenField::create("Ref")->setValue($controller->Title), HiddenField::create("Locale")->setValue($controller->Locale)));
     $actions = new FieldList(FormAction::create('dosave', _t("ContactPage.APPLY", "Send"))->setStyle("success"));
     $validator = ZenValidator::create();
     $validator->addRequiredFields(array('FirstName', 'LastName', 'Email', 'Description'));
     $validator->setConstraint('Email', Constraint_type::create('email'));
     $validator->setConstraint('Description', Constraint_length::create('min', 10));
     parent::__construct($controller, $name, $fields, $actions, $validator);
     if ($this->extend('updateFields', $fields) !== null) {
         $this->setFields($fields);
     }
     if ($this->extend('updateActions', $actions) !== null) {
         $this->setActions($actions);
     }
     // if($this->extend('updateValidator', $requiredFields) !== null) {$this->setValidator($requiredFields);}
     $oldData = Session::get("FormInfo.{$this->FormName()}.data");
     if ($oldData && (is_array($oldData) || is_object($oldData))) {
         $this->loadDataFrom($oldData);
     }
     $this->extend('updateContactInquiryForm', $this);
 }
 /**
  * @param string $url - the url to call via ajax
  * @param array $params - request vars
  * @param string $options - array of options like { "type": "POST", "dataType": "jsonp", "data": { "token": "value" } }
  * @param boolean|string $validator  - custom validator or "reverse"
  * By default, all 2xx ajax returs are considered valid, all others failure.
  * You can show frontend server-side specific error messages by returning a 404 error with the error message in the body of the response
  * */
 public function __construct($url, $params = array(), $options = true, $validator = null)
 {
     $this->url = $url;
     $this->params = $params;
     $this->options = $options;
     if ($validator !== null) {
         $this->validator = $validator;
     }
     // For current version of Parsley, we have defined a custom async validator for default use cases
     if ($this->validator === null && ZenValidator::config()->use_current) {
         $this->validator = 'zenRemote';
     }
     if (is_array($options) && isset($this->options['type'])) {
         $this->method = $this->options['type'];
     }
     parent::__construct();
 }