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


PHP Form::create方法代码示例

本文整理汇总了PHP中Form::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Form::create方法的具体用法?PHP Form::create怎么用?PHP Form::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Form的用法示例。


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

示例1: __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

示例2: __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

示例3: testErrors

 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());
 }
开发者ID:rero26,项目名称:onphp-framework,代码行数:32,代码来源:FormTest.class.php

示例4: Form

 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);
 }
开发者ID:Ariex,项目名称:silverstripe-zenvalidator,代码行数:7,代码来源:ZenValidatorRuleTest.php

示例5: UpdateForm

 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;
 }
开发者ID:spekulatius,项目名称:silverstripe-frontend-dashboards,代码行数:30,代码来源:UserProfileDashlet.php

示例6: index

 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);
 }
开发者ID:helpfulrobot,项目名称:i-lateral-silverstripe-commerce,代码行数:31,代码来源:PayPalHandler.php

示例7: ShortcodeForm

 /**
  * 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;
 }
开发者ID:helpfulrobot,项目名称:sheadawson-silverstripe-shortcodable,代码行数:64,代码来源:ShortcodableController.php

示例8: LinkForm

 /**
  * 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;
 }
开发者ID:sheadawson,项目名称:silverstripe-linkable,代码行数:30,代码来源:LinkField.php

示例9: __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

示例10: AddNewListboxForm

 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;
 }
开发者ID:christopherbolt,项目名称:silverstripe-bolttools,代码行数:27,代码来源:AddNewDropDownField.php

示例11: 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);
 }
开发者ID:helpfulrobot,项目名称:sheadawson-silverstripe-zenvalidator,代码行数:7,代码来源:ZenValidatorTest.php

示例12: testIntegerValues

 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);
 }
开发者ID:onphp-framework,项目名称:onphp-framework,代码行数:7,代码来源:PrimitiveEnumerationTest.class.php

示例13: SelectForm

 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;
 }
开发者ID:sunnysideup,项目名称:silverstripe-electric-vehicle-calculator,代码行数:7,代码来源:EVCSelectPage.php

示例14: MembershipForm

 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;
 }
开发者ID:helpfulrobot,项目名称:silvershop-core,代码行数:8,代码来源:CheckoutStep_Membership.php

示例15: privilegedPortInvalid

 /**
  * @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"]);
 }
开发者ID:onphp-framework,项目名称:onphp-framework,代码行数:11,代码来源:PrimitiveHttpUrlTest.class.php


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