当前位置: 首页>>代码示例>>PHP>>正文


PHP RequiredFields类代码示例

本文整理汇总了PHP中RequiredFields的典型用法代码示例。如果您正苦于以下问题:PHP RequiredFields类的具体用法?PHP RequiredFields怎么用?PHP RequiredFields使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了RequiredFields类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getFrontEndFormValidator

 public function getFrontEndFormValidator($flexi)
 {
     $validator = new RequiredFields();
     foreach ($flexi->FlexiFormFields()->filter('Required', true) as $field) {
         $validator->addRequiredField($field->SafeName());
     }
     return $validator;
 }
开发者ID:helpfulrobot,项目名称:briceburg-silverstripe-flexiform,代码行数:8,代码来源:FlexiFormHandler.php

示例2: get_edit_fields

 static function get_edit_fields($extraFields = null)
 {
     $fields = new FieldSet(new TextField('FirstName', _t('Member.FIRSTNAME', 'First Name')), new TextField('Surname', _t('Member.SURNAME', 'Surname')), new EmailField('Email', _t('Member.EMAIL', 'Email')), new ConfirmedPasswordField('Password', _t('Member.db_Password', 'Password') . ' *'));
     $requiredFields = new RequiredFields('FirstName', 'Surname', 'Email', 'Password');
     if ($extraFields) {
         foreach ($extraFields as $name => $title) {
             $fields->push(new TextField($name, $title));
             $requiredFields->addRequiredField($name);
         }
     }
     return array($fields, $requiredFields);
 }
开发者ID:helpfulrobot,项目名称:sunnysideup-ecommerce-merchants,代码行数:12,代码来源:MerchantAdminDOD.php

示例3: testGetStateWithFieldValidationErrors

 public function testGetStateWithFieldValidationErrors()
 {
     $fields = new FieldList(new TextField('Title'));
     $actions = new FieldList();
     $validator = new RequiredFields('Title');
     $form = new Form(new Controller(), 'TestForm', $fields, $actions, $validator);
     $form->loadDataFrom(['Title' => 'My Title']);
     $validator->validationError('Title', 'Title is invalid', 'error');
     $formSchema = new FormSchema();
     $expected = ['id' => 'TestForm', 'fields' => [['id' => 'Form_TestForm_Title', 'value' => 'My Title', 'messages' => [['value' => 'Title is invalid', 'type' => 'error']], 'valid' => false, 'data' => []], ['id' => 'Form_TestForm_SecurityID', 'value' => $form->getSecurityToken()->getValue(), 'messages' => [], 'valid' => true, 'data' => []]], 'messages' => []];
     $state = $formSchema->getState($form);
     $this->assertInternalType('array', $state);
     $this->assertJsonStringEqualsJsonString(json_encode($expected), json_encode($state));
 }
开发者ID:assertchris,项目名称:silverstripe-framework,代码行数:14,代码来源:FormSchemaTest.php

示例4: __construct

 /**
  * RegistrationForm constructor
  *
  * @param Controller $controller
  * @param String $name
  * @param array $arguments
  */
 public function __construct($controller, $name, $arguments = array())
 {
     /** -----------------------------------------
      * Fields
      * ----------------------------------------*/
     /** @var TextField $firstName */
     $firstName = TextField::create('FirstName');
     $firstName->setAttribute('placeholder', 'Enter your first name')->setAttribute('data-parsley-required-message', 'Please enter your <strong>First Name</strong>')->setCustomValidationMessage('Please enter your <strong>First Name</strong>');
     /** @var EmailField $email */
     $email = EmailField::create('Email');
     $email->setAttribute('placeholder', 'Enter your email address')->setAttribute('data-parsley-required-message', 'Please enter your <strong>Email</strong>')->setCustomValidationMessage('Please enter your <strong>Email</strong>');
     /** @var PasswordField $password */
     $password = PasswordField::create('Password');
     $password->setAttribute('placeholder', 'Enter your password')->setCustomValidationMessage('Please enter your <strong>Password</strong>')->setAttribute('data-parsley-required-message', 'Please enter your <strong>Password</strong>');
     $fields = FieldList::create($email, $password);
     /** -----------------------------------------
      * Actions
      * ----------------------------------------*/
     $actions = FieldList::create(FormAction::create('Register')->setTitle('Register')->addExtraClass('btn--primary'));
     /** -----------------------------------------
      * Validation
      * ----------------------------------------*/
     $required = RequiredFields::create('FirstName', 'Email', 'Password');
     /** @var Form $form */
     $form = Form::create($this, $name, $fields, $actions, $required);
     if ($formData = Session::get('FormInfo.Form_' . $name . '.data')) {
         $form->loadDataFrom($formData);
     }
     parent::__construct($controller, $name, $fields, $actions, $required);
     $this->setAttribute('data-parsley-validate', true);
     $this->addExtraClass('form form--registration');
 }
开发者ID:helpfulrobot,项目名称:ryanpotter-silverstripe-boilerplate,代码行数:39,代码来源:RegistrationForm.php

示例5: __construct

 /**
  * EmailVerificationLoginForm is the same as MemberLoginForm with the following changes:
  *  - The code has been cleaned up.
  *  - A form action for users who have lost their verification email has been added.
  *
  * We add fields in the constructor so the form is generated when instantiated.
  *
  * @param Controller $controller The parent controller, necessary to create the appropriate form action tag.
  * @param string $name The method on the controller that will return this form object.
  * @param FieldList|FormField $fields All of the fields in the form - a {@link FieldList} of {@link FormField} objects.
  * @param FieldList|FormAction $actions All of the action buttons in the form - a {@link FieldList} of {@link FormAction} objects
  * @param bool $checkCurrentUser If set to TRUE, it will be checked if a the user is currently logged in, and if so, only a logout button will be rendered
  */
 function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true)
 {
     $email_field_label = singleton('Member')->fieldLabel(Member::config()->unique_identifier_field);
     $email_field = TextField::create('Email', $email_field_label, null, null, $this)->setAttribute('autofocus', 'autofocus');
     $password_field = PasswordField::create('Password', _t('Member.PASSWORD', 'Password'));
     $authentication_method_field = HiddenField::create('AuthenticationMethod', null, $this->authenticator_class, $this);
     $remember_me_field = CheckboxField::create('Remember', 'Remember me next time?', true);
     if ($checkCurrentUser && Member::currentUser() && Member::logged_in_session_exists()) {
         $fields = FieldList::create($authentication_method_field);
         $actions = FieldList::create(FormAction::create('logout', _t('Member.BUTTONLOGINOTHER', "Log in as someone else")));
     } else {
         if (!$fields) {
             $fields = FieldList::create($authentication_method_field, $email_field, $password_field);
             if (Security::config()->remember_username) {
                 $email_field->setValue(Session::get('SessionForms.MemberLoginForm.Email'));
             } else {
                 // Some browsers won't respect this attribute unless it's added to the form
                 $this->setAttribute('autocomplete', 'off');
                 $email_field->setAttribute('autocomplete', 'off');
             }
         }
         if (!$actions) {
             $actions = FieldList::create(FormAction::create('doLogin', _t('Member.BUTTONLOGIN', "Log in")), new LiteralField('forgotPassword', '<p id="ForgotPassword"><a href="Security/lostpassword">' . _t('Member.BUTTONLOSTPASSWORD', "I've lost my password") . '</a></p>'), new LiteralField('resendEmail', '<p id="ResendEmail"><a href="Security/verify-email">' . _t('MemberEmailVerification.BUTTONLOSTVERIFICATIONEMAIL', "I've lost my verification email") . '</a></p>'));
         }
     }
     if (isset($_REQUEST['BackURL'])) {
         $fields->push(HiddenField::create('BackURL', 'BackURL', $_REQUEST['BackURL']));
     }
     // Reduce attack surface by enforcing POST requests
     $this->setFormMethod('POST', true);
     parent::__construct($controller, $name, $fields, $actions);
     $this->setValidator(RequiredFields::create('Email', 'Password'));
 }
开发者ID:jordanmkoncz,项目名称:silverstripe-memberemailverification,代码行数:46,代码来源:EmailVerificationLoginForm.php

示例6: __construct

 /**
  * @param Controller $controller
  * @param String $name
  * @param array $arguments
  */
 public function __construct($controller, $name, $arguments = array())
 {
     /** =========================================
          * @var EmailField $emailField
          * @var TextField $nameField
          * @var FormAction $submit
          * @var Form $form
         ===========================================*/
     /** -----------------------------------------
      * Fields
      * ----------------------------------------*/
     $emailField = EmailField::create('Email', 'Email Address');
     $emailField->addExtraClass('form-control')->setAttribute('placeholder', 'Email')->setAttribute('data-parsley-required-message', 'Please enter your <strong>Email</strong>')->setCustomValidationMessage('Please enter your <strong>Email</strong>');
     $nameField = TextField::create('Name', 'Name');
     $nameField->setAttribute('placeholder', 'Name')->setAttribute('data-parsley-required-message', 'Please enter your <strong>Name</strong>')->setCustomValidationMessage('Please enter your <strong>Name</strong>');
     $fields = FieldList::create($nameField, $emailField);
     /** -----------------------------------------
      * Actions
      * ----------------------------------------*/
     $submit = FormAction::create('Subscribe');
     $submit->setTitle('SIGN UP')->addExtraClass('button');
     $actions = FieldList::create($submit);
     /** -----------------------------------------
      * Validation
      * ----------------------------------------*/
     $required = RequiredFields::create('Name', 'Email');
     $form = Form::create($this, $name, $fields, $actions, $required);
     if ($formData = Session::get('FormInfo.Form_' . $name . '.data')) {
         $form->loadDataFrom($formData);
     }
     parent::__construct($controller, $name, $fields, $actions, $required);
     $this->setAttribute('data-parsley-validate', true);
     $this->addExtraClass('form');
 }
开发者ID:toastnz,项目名称:quicksilver,代码行数:39,代码来源:SubscriptionForm.php

示例7: put

 public function put($id = null)
 {
     if (empty($id)) {
         new Error("Safety Check ID cannot be empty");
     }
     $fields = array();
     parse_str(file_get_contents("php://input"), $fields);
     $result = RequiredFields::getFields(array('completed' => array('required' => true, 'regex' => '/^(0|1)$/')), $fields);
     $fields = array();
     foreach ($result['data'] as $key => $value) {
         if (!empty($key) && !empty($value)) {
             $fields[$key] = $value;
         }
     }
     if (0 < count($fields)) {
         $this->db->prepareUpdate($fields);
         if ($this->db->update($this->tableName, $id)) {
             $this->get($id);
         } else {
             new Error("Could not update safety check");
         }
     } else {
         new Error("No values to update");
     }
 }
开发者ID:BradlySharpe,项目名称:Sharpies-Auto-Services,代码行数:25,代码来源:SafetyCheck.php

示例8: put

 public function put($id = null)
 {
     if (empty($id)) {
         new Error("Customer ID cannot be empty");
     }
     $fields = array();
     parse_str(file_get_contents("php://input"), $fields);
     $result = RequiredFields::getFields(array('firstname' => array('regex' => '/^.{1,30}$/'), 'lastname' => array('regex' => '/^.{1,30}$/'), 'address' => array('regex' => '/^.{1,100}$/'), 'city' => array('regex' => '/^.{1,50}$/'), 'state' => array('regex' => '/^.{1,20}$/'), 'postcode' => array('regex' => '/^\\d{4}$/')), $fields);
     $fields = array();
     foreach ($result['data'] as $key => $value) {
         if (!empty($key) && !empty($value)) {
             $fields[$key] = $value;
         }
     }
     if (0 < count($fields)) {
         $this->db->prepareUpdate($fields);
         if ($this->db->update($this->tableName, $id)) {
             $this->get($id);
         } else {
             new Error("Could not update customer");
         }
     } else {
         new Error("No values to update");
     }
 }
开发者ID:BradlySharpe,项目名称:Sharpies-Auto-Services,代码行数:25,代码来源:Customer.php

示例9: createValidator

 public function createValidator()
 {
     $validator = RequiredFields::create('PaymentMethod');
     $this->extend('updateValidator', $validator);
     $validator->setForm($this);
     return $validator;
 }
开发者ID:vinstah,项目名称:body,代码行数:7,代码来源:RepayForm.php

示例10: put

 public function put($id = null)
 {
     if (empty($id)) {
         new Error("Item ID cannot be empty");
     }
     $fields = array();
     parse_str(file_get_contents("php://input"), $fields);
     $result = RequiredFields::getFields(array('invoice' => array('regex' => '/^\\d+$/'), 'amount' => array('regex' => '/^([\\d]*\\.[\\d]+|[\\d]+)$/'), 'comment' => array(), 'date' => array('regex' => '/^2\\d{3}\\-[01]\\d\\-[0-3]\\d$/')), $fields);
     $fields = array();
     foreach ($result['data'] as $key => $value) {
         if (!empty($key) && !empty($value)) {
             $fields[$key] = $value;
         }
     }
     if (0 < count($fields)) {
         $this->db->prepareUpdate($fields);
         if ($this->db->update($this->tableName, $id)) {
             $this->get($id);
         } else {
             new Error("Could not update payment");
         }
     } else {
         new Error("No values to update");
     }
 }
开发者ID:BradlySharpe,项目名称:Sharpies-Auto-Services,代码行数:25,代码来源:Payment.php

示例11: put

 public function put($id = null)
 {
     if (empty($id)) {
         new Error("Item ID cannot be empty");
     }
     $fields = array();
     parse_str(file_get_contents("php://input"), $fields);
     $result = RequiredFields::getFields(array('description' => array('regex' => '/^.{1,100}$/'), 'defaultCost' => array('regex' => '/^[-+]?([\\d]*\\.[\\d]+|[\\d]+)$/'), 'defaultQuantity' => array('regex' => '/^[-+]?([\\d]*\\.[\\d]+|[\\d]+)$/'), 'comment' => array('regex' => '/^(0|1)$/'), 'active' => array('regex' => '/^(0|1)$/')), $fields);
     $fields = array();
     foreach ($result['data'] as $key => $value) {
         if (!empty($key) && !empty($value)) {
             $fields[$key] = $value;
         }
     }
     if (0 < count($fields)) {
         $this->db->prepareUpdate($fields);
         if ($this->db->update($this->tableName, $id)) {
             $this->get($id);
         } else {
             new Error("Could not update item");
         }
     } else {
         new Error("No values to update");
     }
 }
开发者ID:BradlySharpe,项目名称:Sharpies-Auto-Services,代码行数:25,代码来源:Item.php

示例12: put

 public function put($customerId = null, $carId = null)
 {
     if (empty($carId)) {
         new Error("Car ID cannot be empty");
     }
     $fields = array();
     parse_str(file_get_contents("php://input"), $fields);
     $result = RequiredFields::getFields(array('owner' => array('regex' => '/^\\d+$/'), 'make' => array('regex' => '/^.{1,100}$/'), 'model' => array('regex' => '/^.{1,100}$/'), 'registration' => array('regex' => '/^[A-Z0-9]{1,6}$/')), $fields);
     $fields = array();
     foreach ($result['data'] as $key => $value) {
         if (!empty($key) && !empty($value)) {
             $fields[$key] = $value;
         }
     }
     if (0 < count($fields)) {
         $this->db->prepareUpdate($fields);
         if ($this->db->update($this->tableName, $carId)) {
             $this->get(array_key_exists('owner', $fields) ? $fields['owner'] : $customerId, $carId);
         } else {
             new Error("Could not update customer");
         }
     } else {
         new Error("No values to update");
     }
 }
开发者ID:BradlySharpe,项目名称:Sharpies-Auto-Services,代码行数:25,代码来源:Car.php

示例13: __construct

 /**
  * @param Controller $controller
  * @param String $name
  * @param array $arguments
  */
 public function __construct($controller, $name, $arguments = array())
 {
     /** -----------------------------------------
      * Fields
      * ----------------------------------------*/
     /** @var EmailField $email */
     $email = EmailField::create('Email', 'Email Address');
     $email->addExtraClass('form-control')->setAttribute('data-parsley-required-message', 'Please enter your <strong>Email</strong>')->setCustomValidationMessage('Please enter your <strong>Email</strong>');
     $fields = FieldList::create($email);
     /** -----------------------------------------
      * Actions
      * ----------------------------------------*/
     $actions = FieldList::create(FormAction::create('Subscribe')->setTitle('Subscribe')->addExtraClass('btn btn-primary'));
     /** -----------------------------------------
      * Validation
      * ----------------------------------------*/
     $required = RequiredFields::create('Email');
     /** @var Form $form */
     $form = Form::create($this, $name, $fields, $actions, $required);
     if ($formData = Session::get('FormInfo.Form_' . $name . '.data')) {
         $form->loadDataFrom($formData);
     }
     parent::__construct($controller, $name, $fields, $actions, $required);
     $this->setAttribute('data-parsley-validate', true);
     $this->addExtraClass('form');
 }
开发者ID:helpfulrobot,项目名称:ryanpotter-silverstripe-boilerplate,代码行数:31,代码来源:SubscriptionForm.php

示例14: __construct

 public function __construct($controller, $name = "PostagePaymentForm")
 {
     // Get delivery data and postage areas from session
     $delivery_data = Session::get("Commerce.DeliveryDetailsForm.data");
     $country = $delivery_data['DeliveryCountry'];
     $postcode = $delivery_data['DeliveryPostCode'];
     $postage_areas = $controller->getPostageAreas($country, $postcode);
     // Loop through all postage areas and generate a new list
     $postage_array = array();
     foreach ($postage_areas as $area) {
         $area_currency = new Currency("Cost");
         $area_currency->setValue($area->Cost);
         $postage_array[$area->ID] = $area->Title . " (" . $area_currency->Nice() . ")";
     }
     $postage_id = Session::get('Commerce.PostageID') ? Session::get('Commerce.PostageID') : 0;
     // Setup postage fields
     $postage_field = CompositeField::create(HeaderField::create("PostageHeader", _t('Commerce.Postage', "Postage")), OptionsetField::create("PostageID", _t('Commerce.PostageSelection', 'Please select your prefered postage'), $postage_array)->setValue($postage_id))->setName("PostageFields")->addExtraClass("unit")->addExtraClass("size1of2")->addExtraClass("unit-50");
     // Get available payment methods and setup payment
     $payment_methods = SiteConfig::current_site_config()->PaymentMethods();
     // Deal with payment methods
     if ($payment_methods->exists()) {
         $payment_map = $payment_methods->map('ID', 'Label');
         $payment_value = $payment_methods->filter('Default', 1)->first()->ID;
     } else {
         $payment_map = array();
         $payment_value = 0;
     }
     $payment_field = CompositeField::create(HeaderField::create('PaymentHeading', _t('Commerce.Payment', 'Payment'), 2), OptionsetField::create('PaymentMethodID', _t('Commerce.PaymentSelection', 'Please choose how you would like to pay'), $payment_map, $payment_value))->setName("PaymentFields")->addExtraClass("unit")->addExtraClass("size1of2")->addExtraClass("unit-50");
     $fields = FieldList::create(CompositeField::create($postage_field, $payment_field)->setName("PostagePaymentFields")->addExtraClass("units-row")->addExtraClass("line"));
     $back_url = $controller->Link("billing");
     $actions = FieldList::create(LiteralField::create('BackButton', '<a href="' . $back_url . '" class="btn btn-red commerce-action-back">' . _t('Commerce.Back', 'Back') . '</a>'), FormAction::create('doContinue', _t('Commerce.PaymentDetails', 'Enter Payment Details'))->addExtraClass('btn')->addExtraClass('commerce-action-next')->addExtraClass('btn-green'));
     $validator = RequiredFields::create(array("PostageID", "PaymentMethod"));
     parent::__construct($controller, $name, $fields, $actions, $validator);
 }
开发者ID:helpfulrobot,项目名称:i-lateral-silverstripe-commerce,代码行数:34,代码来源:PostagePaymentForm.php

示例15: PersonalRegisterForm

 public function PersonalRegisterForm()
 {
     $fields = FieldList::create(array(EmailField::create('Email', '电子邮件'), ConfirmedPasswordField::create('Password', '密码'), TextField::create('FullName', '姓名'), TextField::create('IDCard', '身份证号码'), TextField::create('Phone', '联系电话'), DropdownField::create('OrganizationID', '所属单位名称', Organization::get()->map('ID', 'company_name'))->setEmptyString('请选择')));
     $actions = FieldList::create(array(FormAction::create('doRegisterPersonal', '提交')));
     $required = RequiredFields::create(array('Email', 'Password', 'FullName', 'IDCard', 'Phone', 'OrganizationID'));
     $form = new Form($this, __FUNCTION__, $fields, $actions, $required);
     return $form;
 }
开发者ID:jallen0927,项目名称:lytech,代码行数:8,代码来源:RegisterPage_Controller.php


注:本文中的RequiredFields类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。