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


PHP Form::isValid方法代码示例

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


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

示例1: post

 public function post($id = null)
 {
     if (empty($_POST)) {
         $this->_logger->debug("loading form at {$_SERVER['REQUEST_URI']}");
         if ($id !== null) {
             $post = $this->_factory->get('Post', $id);
             $this->view->aTitle = $post->title;
             $this->view->aBody = $post->body;
         }
         $this->view->display('blog/edit.tpl');
     } else {
         $this->_logger->debug("form at {$_SERVER['REQUEST_URI']} submitted");
         $validators = array('aTitle' => array('NotEmpty', 'messages' => 'Title is required'), 'aBody' => array('NotEmpty', 'messages' => 'Body is required'));
         $form = new Form($validators, $_POST);
         if (!$form->isValid()) {
             $this->_logger->debug("form at {$_SERVER['REQUEST_URI']} submitted but invalid");
             $this->view->assign($_POST);
             $this->view->assign($form->getMessages());
             $this->view->display('blog/edit.tpl');
         } else {
             $this->_logger->debug("form at {$_SERVER['REQUEST_URI']} successful ");
             $post = $this->_factory->get('Post', $id);
             $post->title = $form->getRaw('aTitle');
             $post->body = $form->getRaw('aBody');
             $post->create_dt_tm = date('Y-m-d H:i:s');
             $post->save();
             header('Location: /blog');
             exit;
         }
     }
 }
开发者ID:hellogerard,项目名称:pox-framework,代码行数:31,代码来源:BlogController.php

示例2: testShouldSetNameToCategory

 function testShouldSetNameToCategory()
 {
     $form = new Form(null);
     $this->assertTrue($form->isValid(['name' => 'wheels']));
     $category = $form->getValues();
     $this->assertEquals('wheels', $category['name'], 'should copy name from form to category');
 }
开发者ID:metator,项目名称:application,代码行数:7,代码来源:FormTest.php

示例3: update

 public function update($id = '')
 {
     $page = $this->page($id);
     if (!$page) {
         return response::error(l('pages.error.missing'));
     }
     $blueprint = blueprint::find($page);
     $fields = $blueprint->fields($page);
     $oldTitle = (string) $page->title();
     // trigger the validation
     $form = new Form($fields->toArray());
     $form->validate();
     // fetch the data for the form
     $data = pagedata::createByInput($page, $form->serialize());
     // stop at invalid fields
     if (!$form->isValid()) {
         return response::error(l('pages.show.error.form'), 400, array('fields' => $form->fields()->filterBy('error', true)->pluck('name')));
     }
     try {
         $page->update($data);
         // make sure that the sorting number is correct
         if ($page->isVisible()) {
             $num = api::createPageNum($page);
             if ($num !== $page->num()) {
                 if ($num > 0) {
                     $page->sort($num);
                 }
             }
         }
         history::visit($page->id());
         return response::success('success', array('file' => $page->content()->root(), 'data' => $data, 'uid' => $page->uid(), 'uri' => $page->id()));
     } catch (Exception $e) {
         return response::error($e->getMessage());
     }
 }
开发者ID:muten84,项目名称:luigibifulco.it,代码行数:35,代码来源:pages.php

示例4: index

 public function index()
 {
     $language = OW::getLanguage();
     $billingService = BOL_BillingService::getInstance();
     $adminForm = new Form('adminForm');
     $element = new TextField('creditValue');
     $element->setRequired(true);
     $element->setLabel($language->text('billingcredits', 'admin_usd_credit_value'));
     $element->setDescription($language->text('billingcredits', 'admin_usd_credit_value_desc'));
     $element->setValue($billingService->getGatewayConfigValue('billingcredits', 'creditValue'));
     $validator = new FloatValidator(0.1);
     $validator->setErrorMessage($language->text('billingcredits', 'invalid_numeric_format'));
     $element->addValidator($validator);
     $adminForm->addElement($element);
     $element = new Submit('saveSettings');
     $element->setValue($language->text('billingcredits', 'admin_save_settings'));
     $adminForm->addElement($element);
     if (OW::getRequest()->isPost()) {
         if ($adminForm->isValid($_POST)) {
             $values = $adminForm->getValues();
             $billingService->setGatewayConfigValue('billingcredits', 'creditValue', $values['creditValue']);
             OW::getFeedback()->info($language->text('billingcredits', 'user_save_success'));
         }
     }
     $this->addForm($adminForm);
     $this->setPageHeading(OW::getLanguage()->text('billingcredits', 'config_page_heading'));
     $this->setPageTitle(OW::getLanguage()->text('billingcredits', 'config_page_heading'));
     $this->setPageHeadingIconClass('ow_ic_app');
 }
开发者ID:vazahat,项目名称:dudex,代码行数:29,代码来源:admin.php

示例5: update

 public function update($id)
 {
     $filename = get('filename');
     $page = $this->page($id);
     if (!$page) {
         return response::error(l('files.error.missing.page'));
     }
     $file = $page->file($filename);
     if (!$file) {
         return response::error(l('files.error.missing.file'));
     }
     $blueprint = blueprint::find($page);
     $fields = $blueprint->files()->fields($page);
     // trigger the validation
     $form = new Form($fields->toArray());
     $form->validate();
     // fetch the form data
     $data = filedata::createByInput($file, $form->serialize());
     // stop at invalid fields
     if (!$form->isValid()) {
         return response::error(l('files.show.error.form'), 400, array('fields' => $form->fields()->filterBy('error', true)->pluck('name')));
     }
     try {
         $file->update($data, app::$language);
         return response::success('success', array('data' => $data));
     } catch (Exception $e) {
         return response::error($e->getMessage());
     }
 }
开发者ID:kompuser,项目名称:panel,代码行数:29,代码来源:files.php

示例6: settings

 public function settings()
 {
     $adminForm = new Form('adminForm');
     $language = OW::getLanguage();
     $config = OW::getConfig();
     $element = new TextField('autoclick');
     $element->setRequired(true);
     $validator = new IntValidator(1);
     $validator->setErrorMessage($language->text('autoviewmore', 'admin_invalid_number_error'));
     $element->addValidator($validator);
     $element->setLabel($language->text('autoviewmore', 'admin_auto_click'));
     $element->setValue($config->getValue('autoviewmore', 'autoclick'));
     $adminForm->addElement($element);
     $element = new Submit('saveSettings');
     $element->setValue($language->text('autoviewmore', 'admin_save_settings'));
     $adminForm->addElement($element);
     if (OW::getRequest()->isPost()) {
         if ($adminForm->isValid($_POST)) {
             $values = $adminForm->getValues();
             $config = OW::getConfig();
             $config->saveConfig('autoviewmore', 'autoclick', $values['autoclick']);
             OW::getFeedback()->info($language->text('autoviewmore', 'user_save_success'));
         }
     }
     $this->addForm($adminForm);
 }
开发者ID:vazahat,项目名称:dudex,代码行数:26,代码来源:admin.php

示例7: testHTMLEntities

 public function testHTMLEntities()
 {
     $input = array('Username' => 'gerard', 'Password' => 'pass&');
     $form = new Form($this->_validators, $input);
     $this->assertTrue($form->isValid());
     $this->assertEquals($form->getHTMLEntities('Password'), 'pass&');
 }
开发者ID:hellogerard,项目名称:pox-framework,代码行数:7,代码来源:FormTest.php

示例8: isValid

 public function isValid($data)
 {
     $this->albumPhotosValidator->setAlbumId($data['from-album']);
     if (!empty($data['to-album'])) {
         $this->getElement('to-album')->setRequired()->addValidator(new PHOTO_CLASS_AlbumOwnerValidator());
     }
     return parent::isValid($data);
 }
开发者ID:tammyrocks,项目名称:photo,代码行数:8,代码来源:album_add_form.php

示例9: testIsValid

 /**
  * Test validate
  */
 public function testIsValid()
 {
     $this->form->add('<div>Test</div>');
     $element_valid = $this->getMockBuilder('Jasny\\FormBuilder\\Element')->getMockForAbstractClass();
     $element_valid->expects($this->exactly(2))->method('isValid')->will($this->returnValue(true));
     $element_invalid = $this->getMockBuilder('Jasny\\FormBuilder\\Element')->getMockForAbstractClass();
     $element_invalid->expects($this->once())->method('isValid')->will($this->returnValue(false));
     $this->form->add($element_valid);
     $this->assertTrue($this->form->isValid());
     $this->form->add($element_invalid);
     $this->assertFalse($this->form->isValid());
 }
开发者ID:sachsy,项目名称:formbuilder,代码行数:15,代码来源:FormTest.php

示例10: exampleForm

 private function exampleForm()
 {
     $countries = array('Select your country', 'Europe' => array('CZ' => 'Czech Republic', 'FR' => 'France', 'DE' => 'Germany', 'GR' => 'Greece', 'HU' => 'Hungary', 'IE' => 'Ireland', 'IT' => 'Italy', 'NL' => 'Netherlands', 'PL' => 'Poland', 'SK' => 'Slovakia', 'ES' => 'Spain', 'CH' => 'Switzerland', 'UA' => 'Ukraine', 'GB' => 'United Kingdom'), 'AU' => 'Australia', 'CA' => 'Canada', 'EG' => 'Egypt', 'JP' => 'Japan', 'US' => 'United States', '?' => 'other');
     $sex = array('m' => 'male', 'f' => 'female');
     // Step 1: Define form with validation rules
     $form = new Form();
     // group Personal data
     $form->addGroup('Personal data')->setOption('description', 'We value your privacy and we ensure that the information you give to us will not be shared to other entities.');
     $form->addText('name', 'Your name:', 35)->addRule(Form::FILLED, 'Enter your name');
     $form->addText('age', 'Your age:', 5)->addRule(Form::FILLED, 'Enter your age')->addRule(Form::INTEGER, 'Age must be numeric value')->addRule(Form::RANGE, 'Age must be in range from %.2f to %.2f', array(9.9, 100));
     $form->addRadioList('gender', 'Your gender:', $sex);
     $form->addText('email', 'E-mail:', 35)->setEmptyValue('@')->addCondition(Form::FILLED)->addRule(Form::EMAIL, 'Incorrect E-mail Address');
     // ... then check email
     // group Shipping address
     $form->addGroup('Shipping address')->setOption('embedNext', TRUE);
     $form->addCheckbox('send', 'Ship to address')->addCondition(Form::EQUAL, TRUE)->toggle('sendBox');
     // toggle div #sendBox
     // subgroup
     $form->addGroup()->setOption('container', Html::el('div')->id('sendBox'));
     $form->addText('street', 'Street:', 35);
     $form->addText('city', 'City:', 35)->addConditionOn($form['send'], Form::EQUAL, TRUE)->addRule(Form::FILLED, 'Enter your shipping address');
     $form->addSelect('country', 'Country:', $countries)->skipFirst()->addConditionOn($form['send'], Form::EQUAL, TRUE)->addRule(Form::FILLED, 'Select your country');
     // group Your account
     $form->addGroup('Your account');
     $form->addPassword('password', 'Choose password:', 20)->addRule(Form::FILLED, 'Choose your password')->addRule(Form::MIN_LENGTH, 'The password is too short: it must be at least %d characters', 3);
     $form->addPassword('password2', 'Reenter password:', 20)->addConditionOn($form['password'], Form::VALID)->addRule(Form::FILLED, 'Reenter your password')->addRule(Form::EQUAL, 'Passwords do not match', $form['password']);
     $form->addFile('avatar', 'Picture:')->addCondition(Form::FILLED)->addRule(Form::MIME_TYPE, 'Uploaded file is not image', 'image/*');
     $form->addHidden('userid');
     $form->addTextArea('note', 'Comment:', 30, 5);
     // group for buttons
     $form->addGroup();
     $form->addSubmit('submit1', 'Send');
     // Step 2: Check if form was submitted?
     if ($form->isSubmitted()) {
         // Step 2c: Check if form is valid
         if ($form->isValid()) {
             echo '<h2>Form was submitted and successfully validated</h2>';
             $values = $form->getValues();
             Debug::dump($values);
             // this is the end, my friend :-)
             if (empty($disableExit)) {
                 exit;
             }
         }
     } else {
         // not submitted, define default values
         $defaults = array('name' => 'John Doe', 'userid' => 231, 'country' => 'CZ');
         $form->setDefaults($defaults);
     }
     return $form;
 }
开发者ID:laiello,项目名称:webuntucms,代码行数:51,代码来源:Exec.php

示例11: __construct

 public function __construct()
 {
     parent::__construct();
     $language = OW::getLanguage();
     $form = new Form("change-user-password");
     $form->setId("change-user-password");
     $oldPassword = new PasswordField('oldPassword');
     $oldPassword->setLabel($language->text('base', 'change_password_old_password'));
     $oldPassword->addValidator(new OldPasswordValidator());
     $oldPassword->setRequired();
     $form->addElement($oldPassword);
     $newPassword = new PasswordField('password');
     $newPassword->setLabel($language->text('base', 'change_password_new_password'));
     $newPassword->setRequired();
     $newPassword->addValidator(new NewPasswordValidator());
     $form->addElement($newPassword);
     $repeatPassword = new PasswordField('repeatPassword');
     $repeatPassword->setLabel($language->text('base', 'change_password_repeat_password'));
     $repeatPassword->setRequired();
     $form->addElement($repeatPassword);
     $submit = new Submit("change");
     $submit->setLabel($language->text('base', 'change_password_submit'));
     $form->setAjax(true);
     $form->addElement($submit);
     if (OW::getRequest()->isAjax()) {
         $result = false;
         if ($form->isValid($_POST)) {
             $data = $form->getValues();
             BOL_UserService::getInstance()->updatePassword(OW::getUser()->getId(), $data['password']);
             $result = true;
         }
         echo json_encode(array('result' => $result));
         exit;
     } else {
         $messageError = $language->text('base', 'change_password_error');
         $messageSuccess = $language->text('base', 'change_password_success');
         $js = " owForms['" . $form->getName() . "'].bind( 'success',\n            function( json )\n            {\n            \tif( json.result == true )\n            \t{\n            \t    \$('#TB_closeWindowButton').click();\n            \t    OW.info('{$messageSuccess}');\n                }\n                else\n                {\n                    OW.error('{$messageError}');\n                }\n\n            } ); ";
         OW::getDocument()->addOnloadScript($js);
         $this->addForm($form);
         $language->addKeyForJs('base', 'join_error_password_not_valid');
         $language->addKeyForJs('base', 'join_error_password_too_short');
         $language->addKeyForJs('base', 'join_error_password_too_long');
         //include js
         $onLoadJs = " window.changePassword = new OW_BaseFieldValidators( " . json_encode(array('formName' => $form->getName(), 'responderUrl' => OW::getRouter()->urlFor("BASE_CTRL_Join", "ajaxResponder"), 'passwordMaxLength' => UTIL_Validator::PASSWORD_MAX_LENGTH, 'passwordMinLength' => UTIL_Validator::PASSWORD_MIN_LENGTH)) . ",\n                                                            " . UTIL_Validator::EMAIL_PATTERN . ", " . UTIL_Validator::USER_NAME_PATTERN . " ); ";
         $onLoadJs .= " window.oldPassword = new OW_ChangePassword( " . json_encode(array('formName' => $form->getName(), 'responderUrl' => OW::getRouter()->urlFor("BASE_CTRL_Edit", "ajaxResponder"))) . " ); ";
         OW::getDocument()->addOnloadScript($onLoadJs);
         $jsDir = OW::getPluginManager()->getPlugin("base")->getStaticJsUrl();
         OW::getDocument()->addScript($jsDir . "base_field_validators.js");
         OW::getDocument()->addScript($jsDir . "change_password.js");
     }
 }
开发者ID:vazahat,项目名称:dudex,代码行数:51,代码来源:change_password.php

示例12: validateForm

 public function validateForm($form_slug = "default")
 {
     $valid = false;
     if ($_SERVER['REQUEST_METHOD'] == "POST" && Form::isValid($form_slug, false)) {
         $valid = true;
         Form::clearValues($form_slug);
     } else {
         if ($_SERVER['REQUEST_METHOD'] == "GET" || isset($_POST['RM_CLEAR_ERROR']) && $_POST['RM_CLEAR_ERROR'] === 'true') {
             Form::clearErrors($form_slug);
             Form::clearValues($form_slug);
         }
     }
     return $valid;
 }
开发者ID:developmentDM2,项目名称:What-The-Flicka,代码行数:14,代码来源:class_rm_model_view_handler.php

示例13: load

 /**
  * @param BlockInterface $block
  */
 public function load(BlockInterface $block)
 {
     $this->form = $this->formFactory->create(SubscribeType::class, $this->subscription);
     $this->form->handleRequest($this->request);
     if ($this->form->isValid()) {
         foreach ($this->getMailingLists($block) as $mailingList) {
             $this->subscription->setMailingList($mailingList);
             $this->em->persist($this->subscription);
             $this->em->flush($this->subscription);
             // Reset to add to another mailing list
             $this->em->detach($this->subscription);
             $this->subscription = clone $this->subscription;
             $this->subscription->setId(null);
         }
         $this->subscribed = true;
     }
 }
开发者ID:dylanschoenmakers,项目名称:Cms,代码行数:20,代码来源:SubscribeBlockService.php

示例14: load

 /**
  * @param BlockInterface $block
  */
 public function load(BlockInterface $block)
 {
     $properties = $block->getProperties();
     $opts = array();
     if (isset($properties['responseType']) && $properties['responseType'] == 'redirect') {
         $opts['action'] = $this->router->generate('opifer_mailing_list_subscribe_block', ['id' => $block->getId()]);
     }
     $this->form = $this->formFactory->create(SubscribeType::class, $this->subscription, $opts);
     $this->form->handleRequest($this->request);
     if ($this->form->isValid()) {
         foreach ($this->getMailingLists($block) as $list) {
             $subscription = $this->subscriptionManager->findOrCreate($list, $this->subscription->getEmail());
             $this->subscriptionManager->save($subscription);
         }
         $this->subscribed = true;
     }
 }
开发者ID:Opifer,项目名称:Cms,代码行数:20,代码来源:SubscribeBlockService.php

示例15: update

 public function update($id = '')
 {
     $page = $this->page($id);
     if (!$page) {
         return response::error(l('pages.error.missing'));
     }
     $blueprint = blueprint::find($page);
     $fields = $blueprint->fields($page);
     $oldTitle = (string) $page->title();
     // trigger the validation
     $form = new Form($fields->toArray());
     $form->validate();
     // fetch the data for the form
     $data = pagedata::createByInput($page, $form->serialize());
     // stop at invalid fields
     if (!$form->isValid()) {
         return response::error(l('pages.show.error.form'), 400, array('fields' => $form->fields()->filterBy('error', true)->pluck('name')));
     }
     try {
         PageStore::discard($page);
         $page->update($data);
         // make sure that the sorting number is correct
         if ($page->isVisible()) {
             $num = api::createPageNum($page);
             if ($num !== $page->num()) {
                 if ($num > 0) {
                     $page->sort($num);
                 }
             }
         }
         // get the blueprint of the parent page to find the
         // correct sorting mode for this page
         $parentBlueprint = blueprint::find($page->parent());
         // auto-update the uid if the sorting mode is set to zero
         if ($parentBlueprint->pages()->num()->mode() == 'zero') {
             $uid = str::slug($page->title());
             $page->move($uid);
         }
         history::visit($page->id());
         kirby()->trigger('panel.page.update', $page);
         return response::success('success', array('file' => $page->content()->root(), 'data' => $data, 'uid' => $page->uid(), 'uri' => $page->id()));
     } catch (Exception $e) {
         return response::error($e->getMessage());
     }
 }
开发者ID:madebypost,项目名称:Gulp-Neat-KirbyCMS,代码行数:45,代码来源:pages.php


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