/**
  * 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');
 }
Example #2
0
 /**
  * @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 testErrors()
 {
     $form = Form::create()->add(Primitive::ternary('flag')->setFalseValue('0')->setTrueValue('1'))->add(Primitive::integer('old')->required())->addRule('someRule', Expression::between(FormField::create('old'), '18', '35'));
     //empty import
     $form->import(array())->checkRules();
     //checking
     $expectingErrors = array('old' => Form::MISSING, 'someRule' => Form::WRONG);
     $this->assertEquals($expectingErrors, $form->getErrors());
     $this->assertEquals(Form::MISSING, $form->getError('old'));
     $this->assertEquals(Form::WRONG, $form->getError('someRule'));
     $this->assertTrue($form->hasError('old'));
     $this->assertFalse($form->hasError('flag'));
     //drop errors
     $form->dropAllErrors();
     $this->assertEquals(array(), $form->getErrors());
     //import wrong data
     $form->clean()->importMore(array('flag' => '3', 'old' => '17'))->checkRules();
     //checking
     $expectingErrors = array('flag' => Form::WRONG, 'someRule' => Form::WRONG);
     $this->assertEquals($expectingErrors, $form->getErrors());
     $this->assertTrue($form->hasError('someRule'));
     //marking good and custom check errors
     $form->markGood('someRule')->markCustom('flag', 3);
     $this->assertEquals(array('flag' => 3), $form->getErrors());
     $this->assertFalse($form->hasError('someRule'));
     $this->assertNull($form->getError('someRule'));
     $this->assertEquals(3, $form->getError('flag'));
     //import right data
     $form->dropAllErrors()->clean()->importMore(array('flag' => '1', 'old' => '35'));
     //checking
     $this->assertEquals(array(), $form->getErrors());
 }
 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);
 }
 public function UpdateForm()
 {
     $member = singleton('SecurityContext')->getMember();
     if (!$member) {
         return '';
     }
     // if there's a member profile page availble, use it
     $filter = array();
     if (class_exists('Multisites')) {
         $filter = array('SiteID' => Multisites::inst()->getCurrentSiteId());
     }
     // use member profile page if possible
     if (class_exists('MemberProfilePage') && ($profilePage = MemberProfilePage::get()->filter($filter)->first())) {
         $controller = MemberProfilePage_Controller::create($profilePage);
         $form = $controller->ProfileForm();
         $form->addExtraClass('ajax-form');
         $form->loadDataFrom($member);
         return $form;
     } else {
         $password = new ConfirmedPasswordField('Password', $member->fieldLabel('Password'), null, null, (bool) $this->ID);
         $password->setCanBeEmpty(true);
         $fields = FieldList::create(TextField::create('FirstName', $member->fieldLabel('FirstName')), TextField::create('Surname', $member->fieldLabel('Surname')), EmailField::create('Email', $member->fieldLabel('Email')), $password);
         $actions = FieldList::create($update = FormAction::create('updateprofile', 'Update'));
         $form = Form::create($this, 'UpdateForm', $fields, $actions);
         $form->loadDataFrom($member);
         $this->extend('updateProfileDashletForm', $form);
         return $form;
     }
     return;
 }
 public function index()
 {
     $site = SiteConfig::current_site_config();
     $order = $this->order;
     // Setup the paypal gateway URL
     if (Director::isDev()) {
         $gateway_url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
     } else {
         $gateway_url = "https://www.paypal.com/cgi-bin/webscr";
     }
     $callback_url = Controller::join_links(Director::absoluteBaseURL(), Payment_Controller::config()->url_segment, "callback", $this->payment_gateway->ID);
     $success_url = Controller::join_links(Director::absoluteBaseURL(), Payment_Controller::config()->url_segment, 'complete');
     $error_url = Controller::join_links(Director::absoluteBaseURL(), Payment_Controller::config()->url_segment, 'complete', 'error');
     $back_url = Controller::join_links(Director::absoluteBaseURL(), Checkout_Controller::config()->url_segment, "finish");
     $fields = new FieldList(HiddenField::create('business', null, $this->payment_gateway->BusinessID), HiddenField::create('item_name', null, $site->Title), HiddenField::create('cmd', null, "_cart"), HiddenField::create('paymentaction', null, "sale"), HiddenField::create('invoice', null, $order->OrderNumber), HiddenField::create('custom', null, $order->OrderNumber), HiddenField::create('upload', null, 1), HiddenField::create('discount_amount_cart', null, $order->DiscountAmount), HiddenField::create('amount', null, $order->Total), HiddenField::create('currency_code', null, $site->Currency()->GatewayCode), HiddenField::create('first_name', null, $order->FirstName), HiddenField::create('last_name', null, $order->Surname), HiddenField::create('address1', null, $order->Address1), HiddenField::create('address2', null, $order->Address2), HiddenField::create('city', null, $order->City), HiddenField::create('zip', null, $order->PostCode), HiddenField::create('country', null, $order->Country), HiddenField::create('email', null, $order->Email), HiddenField::create('return', null, $success_url), HiddenField::create('notify_url', null, $callback_url), HiddenField::create('cancel_return', null, $error_url));
     $i = 1;
     foreach ($order->Items() as $item) {
         $fields->add(HiddenField::create('item_name_' . $i, null, $item->Title));
         $fields->add(HiddenField::create('amount_' . $i, null, number_format($item->Price + $item->Tax, 2)));
         $fields->add(HiddenField::create('quantity_' . $i, null, $item->Quantity));
         $i++;
     }
     // Add shipping as an extra product
     $fields->add(HiddenField::create('item_name_' . $i, null, _t("Commerce.Postage", "Postage")));
     $fields->add(HiddenField::create('amount_' . $i, null, number_format($order->PostageCost + $order->PostageTax, 2)));
     $fields->add(HiddenField::create('quantity_' . $i, null, "1"));
     $actions = FieldList::create(LiteralField::create('BackButton', '<a href="' . $back_url . '" class="btn btn-red commerce-action-back">' . _t('Commerce.Back', 'Back') . '</a>'), FormAction::create('Submit', _t('Commerce.ConfirmPay', 'Confirm and Pay'))->addExtraClass('btn')->addExtraClass('btn-green'));
     $form = Form::create($this, 'Form', $fields, $actions)->addExtraClass('forms')->setFormMethod('POST')->setFormAction($gateway_url);
     $this->extend('updateForm', $form);
     return array("Title" => _t('Commerce.CheckoutSummary', "Summary"), "MetaTitle" => _t('Commerce.CheckoutSummary', "Summary"), "Form" => $form);
 }
 /**
  * Provides a GUI for the insert/edit shortcode popup
  * @return Form
  **/
 public function ShortcodeForm()
 {
     if (!Permission::check('CMS_ACCESS_CMSMain')) {
         return;
     }
     Config::inst()->update('SSViewer', 'theme_enabled', false);
     // create a list of shortcodable classes for the ShortcodeType dropdown
     $classList = ClassInfo::implementorsOf('Shortcodable');
     $classes = array();
     foreach ($classList as $class) {
         $classes[$class] = singleton($class)->singular_name();
     }
     // load from the currently selected ShortcodeType or Shortcode data
     $classname = false;
     $shortcodeData = false;
     if ($shortcode = $this->request->requestVar('Shortcode')) {
         $shortcode = str_replace("", '', $shortcode);
         //remove BOM inside string on cursor position...
         $shortcodeData = singleton('ShortcodableParser')->the_shortcodes(array(), $shortcode);
         if (isset($shortcodeData[0])) {
             $shortcodeData = $shortcodeData[0];
             $classname = $shortcodeData['name'];
         }
     } else {
         $classname = $this->request->requestVar('ShortcodeType');
     }
     if ($shortcodeData) {
         $headingText = _t('Shortcodable.EDITSHORTCODE', 'Edit Shortcode');
     } else {
         $headingText = _t('Shortcodable.INSERTSHORTCODE', 'Insert Shortcode');
     }
     // essential fields
     $fields = FieldList::create(array(CompositeField::create(LiteralField::create('Heading', sprintf('<h3 class="htmleditorfield-shortcodeform-heading insert">%s</h3>', $headingText)))->addExtraClass('CompositeField composite cms-content-header nolabel'), LiteralField::create('shortcodablefields', '<div class="ss-shortcodable content">'), DropdownField::create('ShortcodeType', 'ShortcodeType', $classes, $classname)->setHasEmptyDefault(true)->addExtraClass('shortcode-type')));
     // attribute and object id fields
     if ($classname) {
         if (class_exists($classname)) {
             $class = singleton($classname);
             if (is_subclass_of($class, 'DataObject')) {
                 if (singleton($classname)->hasMethod('get_shortcodable_records')) {
                     $dataObjectSource = $classname::get_shortcodable_records();
                 } else {
                     $dataObjectSource = $classname::get()->map()->toArray();
                 }
                 $fields->push(DropdownField::create('id', $class->singular_name(), $dataObjectSource)->setHasEmptyDefault(true));
             }
             if ($attrFields = $classname::shortcode_attribute_fields()) {
                 $fields->push(CompositeField::create($attrFields)->addExtraClass('attributes-composite'));
             }
         }
     }
     // actions
     $actions = FieldList::create(array(FormAction::create('insert', _t('Shortcodable.BUTTONINSERTSHORTCODE', 'Insert shortcode'))->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')->setUseButtonTag(true)));
     // form
     $form = Form::create($this, "ShortcodeForm", $fields, $actions)->loadDataFrom($this)->addExtraClass('htmleditorfield-form htmleditorfield-shortcodable cms-dialog-content');
     if ($shortcodeData) {
         $form->loadDataFrom($shortcodeData['atts']);
     }
     $this->extend('updateShortcodeForm', $form);
     return $form;
 }
 /**
  * The LinkForm for the dialog window
  *
  * @return Form
  **/
 public function LinkForm()
 {
     $link = $this->getLinkObject();
     $action = FormAction::create('doSaveLink', _t('Linkable.SAVE', 'Save'))->setUseButtonTag('true');
     if (!$this->isFrontend) {
         $action->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept');
     }
     $link = null;
     if ($linkID = (int) $this->request->getVar('LinkID')) {
         $link = Link::get()->byID($linkID);
     }
     $link = $link ? $link : singleton('Link');
     $link->setAllowedTypes($this->getAllowedTypes());
     $fields = $link->getCMSFields();
     $title = $link ? _t('Linkable.EDITLINK', 'Edit Link') : _t('Linkable.ADDLINK', 'Add Link');
     $fields->insertBefore(HeaderField::create('LinkHeader', $title), _t('Linkable.TITLE', 'Title'));
     $actions = FieldList::create($action);
     $form = Form::create($this, 'LinkForm', $fields, $actions);
     if ($link) {
         $form->loadDataFrom($link);
         $fields->push(HiddenField::create('LinkID', 'LinkID', $link->ID));
     }
     $this->owner->extend('updateLinkForm', $form);
     return $form;
 }
 /**
  * @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');
 }
 public function AddNewListboxForm()
 {
     $action = FormAction::create('doSave', 'Save')->setUseButtonTag('true');
     if (!$this->isFrontend) {
         $action->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept');
     }
     $model = $this->getModel();
     $link = singleton($model);
     $fields = $link->getCMSFields();
     $title = $this->getDialogTitle() ? $this->getDialogTitle() : 'New Item';
     $fields->insertBefore(HeaderField::create('AddNewHeader', $title), $fields->first()->getName());
     $actions = FieldList::create($action);
     $form = Form::create($this, 'AddNewListboxForm', $fields, $actions);
     $fields->push(HiddenField::create('model', 'model', $model));
     /*
     if($link){
     	$form->loadDataFrom($link);
     	$fields->push(HiddenField::create('LinkID', 'LinkID', $link->ID));
     }
     
     // Chris Bolt, fixed this
     //$this->owner->extend('updateLinkForm', $form);
     $this->extend('updateLinkForm', $form);
     // End Chris Bolt
     */
     return $form;
 }
 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);
 }
 public function testIntegerValues()
 {
     $form = Form::create()->add(Primitive::enumeration('enum')->of('DataType'));
     $form->import(array('enum' => '4097'));
     $this->assertEquals($form->getValue('enum')->getId(), 0x1001);
     $this->assertSame($form->getValue('enum')->getId(), 0x1001);
 }
 function SelectForm()
 {
     $fieldList = new FieldList(NumericField::create("Year", "Manufacturing Year"), DropdownField::create("Make", "Make", array(0 => $this->pleaseSelectPhrase())), DropdownField::create("Model", "Model", array(0 => $this->pleaseSelectPhrase())), DropdownField::create("Type", "Type", array(0 => $this->pleaseSelectPhrase())), NumericField::create("ODO", "Current Odometer (overall distance travelled - as shown in your dashboard"));
     $actions = new FieldList(FormAction::create("doselectform")->setTitle("Start Calculation"));
     $form = Form::create($this, "SelectForm", $fieldList, $actions);
     return $form;
 }
 public function MembershipForm()
 {
     $fields = new FieldList();
     $actions = new FieldList(new FormAction("createaccount", "Create an Account"), new FormAction("guestcontinue", "Continue as Guest"));
     $form = Form::create($this->owner, 'MembershipForm', $fields, $actions);
     $this->owner->extend('updateMembershipForm', $form);
     return $form;
 }
 /**
  * @test
  */
 public function privilegedPortInvalid()
 {
     $form = Form::create()->add(Primitive::httpUrl("url")->setCheckPrivilegedPorts());
     $form->import(array('url' => $this->urlWithPrivilegedPort));
     $errors = $form->getErrors();
     $this->assertTrue(isset($errors["url"]));
     $this->assertEquals(Form::WRONG, $errors["url"]);
 }
Example #16
0
 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;
 }
Example #17
0
 public function SyncButton()
 {
     $fields = FieldList::create(ReadonlyField::create('LastSyncDate', 'Last Sync Date'));
     $actions = FieldList::create(FormAction::create("doSyncFromFeed")->setTitle("Sync Feed to Events"));
     $form = Form::create($this, 'SyncButton', $fields, $actions);
     $form->loadDataFrom($this->data());
     return $form;
 }
Example #18
0
 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;
 }
 public function MembershipForm()
 {
     $fields = FieldList::create();
     $actions = FieldList::create(FormAction::create("createaccount", _t('CheckoutStep_Membership.CreateAccount', "Create an Account", 'This is an option presented to the user')), FormAction::create("guestcontinue", _t('CheckoutStep_Membership.ContinueAsGuest', "Continue as Guest")));
     $form = Form::create($this->owner, 'MembershipForm', $fields, $actions);
     $this->owner->extend('updateMembershipForm', $form);
     return $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;
 }
Example #21
0
 public function form($pseudoClass)
 {
     $suffix = substr($pseudoClass, strlen($pseudoClass) - 4, strlen($pseudoClass));
     if ($suffix != 'Form') {
         $pseudoClass .= 'Form';
     }
     return Form::create()->setClassName($pseudoClass);
 }
 /**
  * Factory for generating a change password form. The form can be expanded
  * using an extension class and calling the updateChangePasswordForm method.
  *
  * @return Form
  */
 public function NotificationForm()
 {
     $fields = FieldList::create(HiddenField::create("ID"), CheckboxField::create("RecieveCommentEmails", _t("Discussions.RecieveCommentEmails", "Recieve emails when one of my discussions is replied to")), CheckboxField::create("RecieveNewDiscussionEmails", _t("Discussions.ReveiveNewDiscussionEmails", "Recieve emails when a new discussion is started")), CheckboxField::create("RecieveLikedEmails", _t("Discussions.ReveiveLikedEmails", "Recieve emails when one of my discussions is liked")), CheckboxField::create("RecieveLikedReplyEmails", _t("Discussions.ReveiveLikedReplyEmails", "Recieve emails when a discussion I like is replied to")));
     $actions = FieldList::create(LiteralField::create("CancelLink", '<a href="' . $this->owner->Link() . '" class="btn btn-red">' . _t("Users.CANCEL", "Cancel") . '</a>'), FormAction::create("doSaveNotificationSettings", _t("Discussions.Save", "Save"))->addExtraClass("btn")->addExtraClass("btn-green"));
     $form = Form::create($this->owner, "NotificationForm", $fields, $actions);
     $this->owner->extend("updateNotificationForm", $form);
     return $form;
 }
Example #23
0
 public function newPlayerForm()
 {
     $fields = new FieldList(TextField::create('FirstName', 'First Name'), TextField::create('Surname', 'Surname'));
     $actions = new FieldList(FormAction::create("doAddplayer")->setTitle("Add player"));
     $required = new RequiredFields('FirstName', 'Surname');
     $form = Form::create($this, 'doAddPlayer', $fields, $actions, $required);
     $form->setTemplate('forms/NewPlayerForm');
     return $form;
 }
Example #24
0
 /**
  * @return mixed
  * Calculate power form
  */
 public function CalcForm()
 {
     $fields = new FieldList($addressField = TextField::create('Address', _t('Home.Address', 'Please input your address')), $suburbField = HiddenField::create('Suburb'), $powerField = TextField::create('PowerAmount', _t('Home.PowerAmount', 'Your monthly power consumption')), $withGasField = CheckboxField::create('WithGas', _t('Home.WithGas', 'Also want to check gas plan?')), $gasField = TextField::create('GasAmount', _t('Home.GasAmount', 'Your monthly gas consumption')));
     $gasField->setAttribute('disabled', 'disabled');
     $actions = new FieldList($submitField = FormAction::create('Calculate', _t('Home.Submit', 'Submit')));
     $validator = new RequiredFields('Address', 'PowerAmount');
     $form = Form::create($this, __FUNCTION__, $fields, $actions, $validator);
     return $form;
 }
 /**
  * @return Form
  */
 public function QuickFeedbackForm()
 {
     $fields = FieldList::create(LiteralField::create('RatingTitle', _t('QuickFeedback.Title', '<h4>Was this article helpful?</h4>')), ButtonGroupField::create('Rating', '', array('1' => _t('QuickFeedback.Yes', 'Yes'), '0' => _t('QuickFeedback.No', 'No'))), TextareaField::create('Comment', _t('QuickFeedback.Comment', 'Comment')));
     if ((bool) Config::inst()->get('QuickFeedbackExtension', 'redirect_field')) {
         $fields->push(HiddenField::create('Redirect', null, $_SERVER['REQUEST_URI']));
     }
     $form = Form::create($this->owner, 'QuickFeedbackForm', $fields, FieldList::create(FormAction::create('doSubmit', _t('QuickFeedback.Submit', 'Submit'))));
     return $form;
 }
Example #26
0
 public function MovieSelector()
 {
     $movies = Movie::get();
     $map = $movies->map('ID', 'Title')->toArray();
     $form = Form::create($this, __FUNCTION__, FieldList::create(DropdownField::create('Movie', 'Movie', $map)), FieldList::create(FormAction::create('selectMovie', 'OK')->addExtraClass('btn btn-default-color btn-lg')));
     //TODO setTemplate
     //$form->setTemplate('MyCustomField');
     return $form;
 }
 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;
 }
 /**
  * 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;
 }
 /**
  * Default Action
  *
  */
 public function index()
 {
     // Setup payment gateway form
     $back_url = Controller::join_links(Director::absoluteBaseURL(), Checkout_Controller::config()->url_segment, "finish");
     $fields = FieldList::create(HiddenField::create('navigate'), HiddenField::create('VPSProtocol', null, $this->payment_gateway->ProtocolVersion), HiddenField::create('TxType', null, 'PAYMENT'), HiddenField::create('Vendor', null, $this->payment_gateway->VendorName), HiddenField::create('Crypt', null, $this->gateway_data()));
     $actions = FieldList::create(LiteralField::create('BackButton', '<a href="' . $back_url . '" class="btn btn-red commerce-action-back">' . _t('Commerce.Back', 'Back') . '</a>'), FormAction::create('Submit', _t('Commerce.ConfirmPay', 'Confirm and Pay'))->addExtraClass('btn')->addExtraClass('btn-green'));
     $form = Form::create($this, 'Form', $fields, $actions)->addExtraClass('forms')->setFormMethod('POST')->setFormAction($this->payment_gateway->GatewayURL());
     $this->extend('updateForm', $form);
     return array('Title' => _t('Commerce.CheckoutSummary', "Summary"), 'MetaTitle' => _t('Commerce.CheckoutSummary', "Summary"), "Form" => $form);
 }
 public function getCMSFields()
 {
     if (!$this->getRecord()) {
         return FieldList::create();
     }
     $fields = $this->getRecord()->getCMSFields();
     $fields->unshift(new LiteralField("stat", "<h3 style='margin-left:10px;'>Status: " . $this->getRecord()->getStatus() . "</h3>"));
     // Create a dummy form so we can get access to loadDataFrom(). :-(
     return Form::create(Controller::curr(), "dummy", $fields, FieldList::create())->loadDataFrom($this->getRecord())->Fields()->makeReadonly();
 }