public function getFrontEndFormValidator($flexi) { $validator = new RequiredFields(); foreach ($flexi->FlexiFormFields()->filter('Required', true) as $field) { $validator->addRequiredField($field->SafeName()); } return $validator; }
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); }
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)); }
/** * Check that an {@link Attribute} Title is unique. * * @param Array $data Submitted data * @return Boolean Returns TRUE if the submitted data is valid, otherwise FALSE. */ function php($data) { $valid = parent::php($data); $newTitle = isset($data['Title']) ? $data['Title'] : null; if ($newTitle) { $existingTitles = DataObject::get('Attribute'); $existingTitles = $existingTitles->map('ID', 'Title'); if (isset($data['ID'])) { unset($existingTitles[$data['ID']]); } if (in_array($newTitle, $existingTitles)) { $valid = false; $this->validationError("Title", "Title already exists, please choose a different one.", 'bad'); } } /* //If invalid tidy up empty Attributes in the DB if (!$valid) { $emptyAttributes = DataObject::get( 'Attribute', '"Attribute"."Title" IS NULL AND "Attribute"."Label" IS NULL' ); if ($emptyAttributes && $emptyAttributes->exists()) foreach ($emptyAttributes as $attr) { $attr->delete(); } } */ return $valid; }
/** * 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'); }
function php($data) { $valid = parent::php($data); // if we are in a complex table field popup, use ctf[childID], else use ID if (isset($_REQUEST['ctf']['childID'])) { $id = $_REQUEST['ctf']['childID']; } else { $id = $this->form->record->ID; } if (isset($id)) { if (isset($_REQUEST['ctf']['ClassName'])) { $class = $_REQUEST['ctf']['ClassName']; } else { $class = $this->form->record->class; } $object = $class::get()->byId($id); if ($object) { foreach ($this->required_files_fields as $key => $value) { $key = is_string($key) ? $key : $value; $fileId = $object->{$key}()->ID; if (!$fileId) { $name = isset($value) && is_array($value) && array_key_exists('Name', $value) ? $value['Name'] : $key; $errorMessage = sprintf(_t('Form.FIELDISREQUIRED', '%s is required') . '.', strip_tags('"' . $name . '"')); $this->validationError($key, $errorMessage, "required"); $valid = false; break; } } } } return $valid; }
/** * 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')); }
/** * @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'); }
public function php($data) { $member = $this->member; $valid = true; foreach ($this->unique as $field) { $other = DataObject::get_one('Member', sprintf('"%s" = \'%s\'', Convert::raw2sql($field), Convert::raw2sql($data[$field]))); if ($other && (!$this->member || !$this->member->exists() || $other->ID != $this->member->ID)) { $fieldInstance = $this->form->Fields()->dataFieldByName($field); if ($fieldInstance->getCustomValidationMessage()) { $message = $fieldInstance->getCustomValidationMessage(); } else { $message = sprintf(_t('MemberProfiles.MEMBERWITHSAME', 'There is already a member with the same %s.'), $field); } $valid = false; $this->validationError($field, $message, 'required'); } } // Create a dummy member as this is required for custom password validators if (isset($data['Password']) && $data['Password'] !== "") { if (is_null($member)) { $member = Member::create(); } if ($validator = $member::password_validator()) { $results = $validator->validate($data['Password'], $member); if (!$results->valid()) { $valid = false; foreach ($results->messageList() as $key => $value) { $this->validationError('Password', $value, 'required'); } } } } return $valid && parent::php($data); }
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"); } }
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"); } }
public function createValidator() { $validator = RequiredFields::create('PaymentMethod'); $this->extend('updateValidator', $validator); $validator->setForm($this); return $validator; }
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"); } }
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"); } }
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"); } }
/** * @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'); }
/** * Currently not used * * TODO could use this to validate variations etc. perhaps * * @param Array $data Submitted data * @return Boolean Returns TRUE if the submitted data is valid, otherwise FALSE. */ function php($data) { $valid = parent::php($data); //$this->validationError("", "This is a test error message for the Title.", 'bad'); //$valid = false; return $valid; }
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); }
public function php($data) { if (!parent::php($data)) { return false; } // Skip unsaved records if (empty($data['ID']) || !is_numeric($data['ID'])) { return true; } $fields = EditableFormField::get()->filter('ParentID', $data['ID'])->sort('"Sort" ASC'); // Current nesting $stack = array(); $conditionalStep = false; // Is the current step conditional? foreach ($fields as $field) { if ($field instanceof EditableFormStep) { // Page at top level, or after another page is ok if (empty($stack) || count($stack) === 1 && $stack[0] instanceof EditableFormStep) { $stack = array($field); $conditionalStep = $field->DisplayRules()->count() > 0; continue; } $this->validationError('FormFields', _t("UserFormValidator.UNEXPECTED_BREAK", "Unexpected page break '{name}' inside nested field '{group}'", array('name' => $field->CMSTitle, 'group' => end($stack)->CMSTitle)), 'error'); return false; } // Validate no pages if (empty($stack)) { $this->validationError('FormFields', _t("UserFormValidator.NO_PAGE", "Field '{name}' found before any pages", array('name' => $field->CMSTitle)), 'error'); return false; } // Nest field group if ($field instanceof EditableFieldGroup) { $stack[] = $field; continue; } // Unnest field group if ($field instanceof EditableFieldGroupEnd) { $top = end($stack); // Check that the top is a group at all if (!$top instanceof EditableFieldGroup) { $this->validationError('FormFields', _t("UserFormValidator.UNEXPECTED_GROUP_END", "'{name}' found without a matching group", array('name' => $field->CMSTitle)), 'error'); return false; } // Check that the top is the right group if ($top->EndID != $field->ID) { $this->validationError('FormFields', _t("UserFormValidator.WRONG_GROUP_END", "'{name}' found closes the wrong group '{group}'", array('name' => $field->CMSTitle, 'group' => $top->CMSTitle)), 'error'); return false; } // Unnest group array_pop($stack); } // Normal field type if ($conditionalStep && $field->Required) { $this->validationError('FormFields', _t("UserFormValidator.CONDITIONAL_REQUIRED", "Required field '{name}' cannot be placed within a conditional page", array('name' => $field->CMSTitle)), 'error'); return false; } } return true; }
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; }
function TypoForm() { $array = array('green', 'yellow', 'blue', 'pink', 'orange'); $form = new Form($this, 'TestForm', $fields = FieldList::create(HeaderField::create('HeaderField1', 'HeaderField Level 1', 1), LiteralField::create('LiteralField', '<p>All fields up to EmailField are required and should be marked as such</p>'), TextField::create('TextField1', 'Text Field Example 1'), TextField::create('TextField2', 'Text Field Example 2'), TextField::create('TextField3', 'Text Field Example 3'), TextField::create('TextField4', ''), HeaderField::create('HeaderField2b', 'Field with right title', 2), $textAreaField = new TextareaField('TextareaField', 'Textarea Field'), EmailField::create('EmailField', 'Email address'), HeaderField::create('HeaderField2c', 'HeaderField Level 2', 2), DropdownField::create('DropdownField', 'Dropdown Field', array(0 => '-- please select --', 1 => 'test AAAA', 2 => 'test BBBB')), OptionsetField::create('OptionSF', 'Optionset Field', $array), CheckboxSetField::create('CheckboxSF', 'Checkbox Set Field', $array), CountryDropdownField::create('CountryDropdownField', 'Countries'), CurrencyField::create('CurrencyField', 'Bling bling', '$123.45'), HeaderField::create('HeaderField3', 'Other Fields', 3), NumericField::create('NumericField', 'Numeric Field '), DateField::create('DateField', 'Date Field'), DateField::create('DateTimeField', 'Date and Time Field'), CheckboxField::create('CheckboxField', 'Checkbox Field')), $actions = FieldList::create(FormAction::create('submit', 'Submit Button')), $requiredFields = RequiredFields::create('TextField1', 'TextField2', 'TextField3', 'ErrorField1', 'ErrorField2', 'EmailField', 'TextField3', 'RightTitleField', 'CheckboxField', 'CheckboxSetField')); $textAreaField->setColumns(45); $form->setMessage('warning message', 'warning'); return $form; }
public function ApplicationForm() { $fields = FieldList::create(TextField::create('Name', 'Full name'), EmailField::create('Email', 'Email address'), PhoneNumberField::create('Phone', 'Contact Phone number'), DropdownField::create('JobID', 'Which job are you applying for?', $this->AvailableJobs()->map('ID', 'Title'))->setEmptyString('(Select)'), TextareaField::create('Application', 'Enter your experience and skills')); $actions = FieldList::create(FormAction::create('processApplication', 'Apply')); $validator = RequiredFields::create(array('Name', 'Email', 'Phone', 'JobID', 'Application')); $form = Form::create($this, 'ApplicationForm', $fields, $actions, $validator); return $form; }
public function CommentForm() { $form = Form::create($this, __FUNCTION__, FieldList::create(TextField::create('Name', '')->setAttribute('placeholder', 'Name*')->addExtraClass('form-control'), EmailField::create('Email', '')->setAttribute('placeholder', 'Email*')->addExtraClass('form-control'), TextareaField::create('Comment', '')->setAttribute('placeholder', 'Comment*')->addExtraClass('form-control')), FieldList::create(FormAction::create('handleComment', 'Post Comment')->setUseButtonTag(true)->addExtraClass('btn btn-default-color btn-lg')), RequiredFields::create('Name', 'Email', 'Comment')); $form->addExtraClass('form-style'); $data = Session::get("FormData.{$form->getName()}.data"); //using the tirnary operator if $data exist... return $data ? $form->loadDataFrom($data) : $form; }
/** * Creates a form to set a password * * @return Form */ public function SetPasswordForm() { if (!Member::currentUser()) { return false; } $form = Form::create($this->owner, FieldList::create(PasswordField::create('Password', 'Password'), PasswordField::Create('Password_confirm', 'Confirm password'), HiddenField::create('BackURL', '', $this->owner->requestVar('BackURL'))), FieldList::create(FormAction::create('doSetPassword', 'Set my password')), RequiredFields::create('Password', 'Password_confirm')); return $form; }
/** * Set the required form fields for this gateway, taking those * defined in Gateway in to account. */ public static function getCMSValidator() { //Get required fields from Gateway DataObject. $parent_required = is_array(parent::getCMSValidator()) ? parent::getCMSValidator() : array(); //Specify our own required fields. $required = array("EmailAddress", "PDTToken"); //Return the required fields. return RequiredFields::create(array_merge($parent_required, $required)); }
public function php($data) { $valid = parent::php($data); if ($valid && !$this->form->getBuyable($_POST)) { $this->validationError("", "This product is not available with the selected options."); $valid = false; } return $valid; }
public function CommentForm() { $form = Form::create($this, __FUNCTION__, FieldList::create(TextField::create('Name', ''), EmailField::create('Email', ''), TextareaField::create('Comment', '')), FieldList::create(FormAction::create('handleComment', 'Post Comment')->setUseButtonTag(true)->addExtraClass('btn btn-default-color btn-lg')), RequiredFields::create('Name', 'Email', 'Comment'))->addExtraClass('form-style'); foreach ($form->Fields() as $field) { $field->addExtraClass('form-control')->setAttribute('placeholder', $field->getName() . '*'); } $data = Session::get("FormData.{$form->getName()}.data"); return $data ? $form->loadDataFrom($data) : $form; }
/** * Set the required form fields for this payment record, taking those * defined in Payment in to account. */ public static function getCMSValidator() { //Get required fields from Courier DataObject. $parent_required = is_array(parent::getCMSValidator()) ? parent::getCMSValidator() : array(); //Specify our own required fields. $required = array("txn_id"); //Return the required fields. return RequiredFields::create(array_merge($parent_required, $required)); }
public function php($data) { $valid = parent::php($data); if ($valid && !$this->form->getBuyable($_POST)) { $this->validationError("", _t('VariationForm.PRODUCT_NOT_AVAILABLE', "This product is not available with the selected options.")); $valid = false; } return $valid; }
/** * Form used for adding or editing addresses */ public function AddressForm() { $personal_fields = CompositeField::create(HeaderField::create('PersonalHeader', _t('Checkout.PersonalDetails', 'Personal Details'), 2), TextField::create('FirstName', _t('Checkout.FirstName', 'First Name(s)')), TextField::create('Surname', _t('Checkout.Surname', 'Surname')), CheckboxField::create('Default', _t('Checkout.DefaultAddress', 'Default Address?'))->setRightTitle(_t('Checkout.Optional', 'Optional')))->setName("PersonalFields")->addExtraClass('unit')->addExtraClass('size1of2')->addExtraClass('unit-50'); $address_fields = CompositeField::create(HeaderField::create('AddressHeader', _t('Checkout.Address', 'Address'), 2), TextField::create('Address1', _t('Checkout.Address1', 'Address Line 1')), TextField::create('Address2', _t('Checkout.Address2', 'Address Line 2'))->setRightTitle(_t('Checkout.Optional', 'Optional')), TextField::create('City', _t('Checkout.City', 'City')), TextField::create('PostCode', _t('Checkout.PostCode', 'Post Code')), CountryDropdownField::create('Country', _t('Checkout.Country', 'Country'))->setAttribute("class", 'countrydropdown dropdown'))->setName("AddressFields")->addExtraClass('unit')->addExtraClass('size1of2')->addExtraClass('unit-50'); $fields = FieldList::create(HiddenField::create("ID"), HiddenField::create("OwnerID"), CompositeField::create($personal_fields, $address_fields)->setName("DeliveryFields")->addExtraClass('line')->addExtraClass('units-row')); $actions = FieldList::create(LiteralField::create('BackButton', '<a href="' . $this->owner->Link('addresses') . '" class="btn btn-red">' . _t('Checkout.Cancel', 'Cancel') . '</a>'), FormAction::create('doSaveAddress', _t('Checkout.Add', 'Add'))->addExtraClass('btn')->addExtraClass('btn-green')); $validator = RequiredFields::create(array('FirstName', 'Surname', 'Address1', 'City', 'PostCode', 'Country')); $form = Form::create($this->owner, "AddressForm", $fields, $actions, $validator); return $form; }