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


PHP Form类代码示例

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


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

示例1: edit

 /**
  * @abstract Displays and processes the edit news form
  * @param integer $id
  * @access public
  */
 public function edit($id = false)
 {
     if (!files()->setUploadDirectory()) {
         sml()->say("The file upload directory does not appear to be writable. Please create the folder and set proper permissions.");
     }
     $form = new Form('news', $id);
     if (!$id) {
         $form->setCurrentValue('timestamp', date("Y-m-d H:i:s"));
     }
     // if form has been submitted
     if ($form->isSubmitted()) {
         $file = files()->upload('pdf_filename');
         if (is_array($file) && !empty($file[0])) {
             $form->setCurrentValue('pdf_filename', $file[0]['file_name']);
         }
         if ($form->save($id)) {
             sml()->say('News entry has successfully been updated.');
             router()->redirect('view');
         }
     }
     // make sure the template has access to all current values
     $data['form'] = $form;
     template()->addCss('admin/datepicker.css');
     template()->addJs('admin/datepicker.js');
     template()->addJs('edit.js');
     template()->display($data);
 }
开发者ID:viveleroi,项目名称:AspenMSM,代码行数:32,代码来源:News_Admin.php

示例2: setForm

 public function setForm(Form &$form, array $request)
 {
     $errors = array();
     $form->befor_set();
     $reflex = new ReflectionObject($form);
     $propts = $reflex->getParentClass()->getProperties();
     foreach ($propts as $propt) {
         $name = $propt->getName();
         $exis = method_exists($form, self::VALIDATE . $name);
         $value = isset($request[$name]) ? $request[$name] : null;
         $valid = self::VALIDATE . $name;
         $setvl = self::SET_METHOD . ucfirst($name);
         $respn = $exis ? $form->{$valid}($value) : true;
         if ($respn === true) {
             if (method_exists($form, $setvl)) {
                 if ($value != null) {
                     $form->{$setvl}($value);
                 }
             } else {
                 if ($value != null) {
                     $propt->setAccessible(true);
                     $propt->setValue($form, $value);
                     $propt->setAccessible(false);
                 }
             }
         } else {
             $errors[$name] = $respn;
         }
     }
     $form->after_set();
     return count($errors) > 0 ? $errors : true;
 }
开发者ID:exildev,项目名称:corvus,代码行数:32,代码来源:View.php

示例3: toBoolean

 public function toBoolean(Form $form)
 {
     $left = $form->toFormValue($this->left);
     $right = $form->toFormValue($this->right);
     $value = $form->toFormValue($this->field);
     return $left <= $value && $value <= $right;
 }
开发者ID:onphp-framework,项目名称:onphp-framework,代码行数:7,代码来源:LogicalBetween.class.php

示例4: 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

示例5: Form

 function Form()
 {
     $form = new Form($this, 'Form', new FieldList(new EmailField('Email')), new FieldList(new FormAction('doSubmit')), new RequiredFields('Email'));
     // Disable CSRF protection for easier form submission handling
     $form->disableSecurityToken();
     return $form;
 }
开发者ID:jakedaleweb,项目名称:AtomCodeChallenge,代码行数:7,代码来源:EmailFieldTest.php

示例6: saveNewsArticle

 function saveNewsArticle($data, Form $form)
 {
     try {
         $form->clearMessage();
         $form->resetValidation();
         if ($data['newsID']) {
             $this->manager->updateNews($data);
         } else {
             $this->manager->postNews($data);
         }
         Session::clear("FormInfo.Form_NewsRequestForm.data");
         return Controller::curr()->redirect('/news-add/?saved=1');
     } catch (EntityValidationException $ex1) {
         $messages = $ex1->getMessages();
         $msg = $messages[0];
         $form->addErrorMessage('Headline', $msg['message'], 'bad');
         SS_Log::log($msg['message'], SS_Log::ERR);
         // Load errors into session and post back
         Session::set("FormInfo.Form_NewsRequestForm.data", $data);
         return $this->redirectBack();
     } catch (Exception $ex) {
         $form->addErrorMessage('Headline', 'Server Error', 'bad');
         SS_Log::log($ex->getMessage(), SS_Log::ERR);
         // Load errors into session and post back
         Session::set("FormInfo.Form_NewsRequestForm.data", $data);
         return $this->redirectBack();
     }
 }
开发者ID:OpenStackweb,项目名称:openstack-org,代码行数:28,代码来源:NewsRequestPage.php

示例7: _createForgotPassForm

 public function _createForgotPassForm()
 {
     $form = new Form();
     $form->action = "/forgotpass";
     $form->add(EmailField::name('email')->label('Email')->help('What is your email address?')->required(true));
     return $form;
 }
开发者ID:JoonasMelin,项目名称:BotQueue,代码行数:7,代码来源:auth.php

示例8: QuickDraftSave

 /**
  * Form Handler to save a content quick create.
  *
  * @param Form $form
  *
  * @return string|bool
  */
 public static function QuickDraftSave(Form $form)
 {
     if (!$form->getElementValue('title')) {
         \Core\set_message('All pages must have titles.', 'error');
         return false;
     }
     /** @var $model ContentModel */
     $model = new ContentModel();
     /** @var $page PageModel Page object for this model, already linked up! */
     $page = $model->getLink('Page');
     // The content nickname is derived from the page title.
     $model->set('nickname', $form->getElementValue('title'));
     $model->save();
     $ins = new InsertableModel();
     $ins->set('site', $page->get('site'));
     $ins->set('baseurl', '/content/view/' . $model->get('id'));
     $ins->set('name', 'body');
     $ins->set('value', '<p>' . nl2br($form->getElementValue('content')) . '</p>');
     $ins->save();
     $page->set('title', $form->getElementValue('title'));
     $page->set('published_status', 'draft');
     $page->set('editurl', '/content/edit/' . $model->get('id'));
     $page->set('deleteurl', '/content/delete/' . $model->get('id'));
     $page->set('component', 'content');
     $page->save();
     return true;
 }
开发者ID:nicholasryan,项目名称:CorePlus,代码行数:34,代码来源:ContentAdminWidget.php

示例9: updateEditForm

 public function updateEditForm(\Form $form)
 {
     $record = $form->getRecord();
     $fields = $form->Fields()->dataFields();
     $separator = HasOneEditDataObjectExtension::separator;
     foreach ($fields as $name => $field) {
         // Replace shortcuts for separator
         $name = str_replace(array(':', '/'), $separator, $name);
         if (!strpos($name, $separator)) {
             // Also skip $name that starts with a separator
             continue;
         }
         $field->setName($name);
         if (!$record) {
             // No record to set value from
             continue;
         }
         if ($field->Value()) {
             // Skip fields that already have a value
             continue;
         }
         list($hasone, $key) = explode($separator, $name, 2);
         if ($record->has_one($hasone) || $record->belongs_to($hasone)) {
             $rel = $record->getComponent($hasone);
             // Copied from loadDataFrom()
             $exists = isset($rel->{$key}) || $rel->hasMethod($key) || $rel->hasMethod('hasField') && $rel->hasField($key);
             if ($exists) {
                 $value = $rel->__get($key);
                 $field->setValue($value);
             }
         }
     }
 }
开发者ID:helpfulrobot,项目名称:lekoala-silverstripe-form-extras,代码行数:33,代码来源:HasOneEditUpdateFormExtension.php

示例10: generateFormID

 /**
  * @param Form $form
  *
  * @return string
  */
 public function generateFormID($form)
 {
     if ($id = $form->getHTMLID()) {
         return Convert::raw2htmlid($id);
     }
     return Convert::raw2htmlid(get_class($form) . '_' . str_replace(array('.', '/'), '', $form->getName()));
 }
开发者ID:ivoba,项目名称:silverstripe-framework,代码行数:12,代码来源:FormTemplateHelper.php

示例11: _buildRegistrationForm

 protected function _buildRegistrationForm()
 {
     $Form = new Form('logon', $this->getRouter(), $this->getRequest());
     $Form->attach(new FormFieldset('personalInfo'));
     $Form->personalInfo->setLegend('Personal Info');
     $FormNoteInfo = new FormNote('info', FormNote::POSITIONRIGHT);
     $FormNoteInfo->addSection('First and Last Name', 'Enter your first and last name separately into the labeled text input boxes.');
     $FormNoteInfo->addSection('E-Mail Address', array('Enter a valid e-mail address into the labeled text input box; this value will also be your username to log onto this website.', 'Also note that to activate your account you will need to follow a link in an activation e-mail sent to this address. Make sure this is a valid e-mail.'));
     $FormNoteInfo->addSection('Password', 'You must enter a strong password that is at least six characters and contains at least one letter, one number, and one symbol.');
     $Form->personalInfo->attach($FormNoteInfo);
     $FormNoteUsage = new FormNote('logonmessage', FormNote::POSITIONNORMAL);
     $FormNoteUsage->addSection(false, 'Please completely fill out the below information. All fields are required.');
     $Form->personalInfo->attach($FormNoteUsage);
     $Form->personalInfo->attach(new FormInput('firstName', 'First Name'));
     $Form->personalInfo->firstName->restrict(new FormRestrictionNotEmpty());
     $Form->personalInfo->firstName->restrict(new FormRestrictionAlphanumeric());
     $Form->personalInfo->firstName->restrict(new FormRestrictionMaxLength(48));
     $Form->personalInfo->attach(new FormInput('lastName', 'Last Name'));
     $Form->personalInfo->lastName->restrict(new FormRestrictionNotEmpty());
     $Form->personalInfo->lastName->restrict(new FormRestrictionAlphanumeric());
     $Form->personalInfo->lastName->restrict(new FormRestrictionMaxLength(48));
     $Form->personalInfo->attach(new FormInput('email', 'E-Mail Address'));
     $Form->personalInfo->email->restrict(new FormRestrictionNotEmpty());
     $Form->personalInfo->email->restrict(new FormRestrictionEmail());
     $Form->personalInfo->email->restrict(new FormRestrictionMaxLength(48));
     $Form->personalInfo->attach(new FormInput('password', 'Password', 'password'));
     $Form->personalInfo->password->restrict(new FormRestrictionNotEmpty());
     $Form->personalInfo->password->restrict(new FormRestrictionMinLength(6));
     $Form->personalInfo->password->restrict(new FormRestrictionGoodPassword());
     $Form->personalInfo->attach(new FormInput('passwordc', 'Password (Confirm)', 'password'));
     $Form->personalInfo->passwordc->restrict(new FormRestrictionSameAsField($Form->personalInfo->password));
     $Form->personalInfo->attach(new FormInputSubmit('Register'));
     return $Form;
 }
开发者ID:robfrawley,项目名称:cad,代码行数:34,代码来源:ControllerRegister.php

示例12: updateLinkForm

 function updateLinkForm(Form $form)
 {
     $linkType = null;
     $fieldList = null;
     $fields = $form->Fields();
     //->fieldByName('Heading');
     foreach ($fields as $field) {
         $linkType = $field->fieldByName('LinkType');
         $fieldList = $field;
         if ($linkType) {
             break;
         }
         //break once we have the object
     }
     $source = $linkType->getSource();
     $source['document'] = 'Download a document';
     $linkType->setSource($source);
     $addExistingField = new DMSDocumentAddExistingField('AddExisting', 'Add Existing');
     $addExistingField->setForm($form);
     $addExistingField->setUseFieldClass(false);
     $fieldList->insertAfter($addExistingField, 'Description');
     //		Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/behaviour/behaviour.js");
     //		Requirements::javascript(SAPPHIRE_DIR . "/javascript/tiny_mce_improvements.js");
     //
     //		// create additional field, rebase to 'documents' directory
     //		$documents = new TreeDropdownField('document', 'Document', 'File', 'ID', 'DocumentDropdownTitle', true);
     //		$documents->setSearchFunction(array($this, 'documentSearchCallback'));
     //		$baseFolder = Folder::find_or_make(Document::$directory);
     //		$documents->setTreeBaseID($baseFolder->ID);
     //return $form;
 }
开发者ID:helpfulrobot,项目名称:silverstripe-dms,代码行数:31,代码来源:DocumentHtmlEditorFieldToolbar.php

示例13: createUser

 /**
  * @param \Symfony\Component\Form\Form $form
  * @param \AppBundle\Entity\User $user
  * @return bool
  */
 public function createUser(Form $form, User $user) : bool
 {
     $return = false;
     if (!$this->checkUsername($user->getUsername())) {
         $return = true;
         $form->get('username')->addError(new FormError($this->translator->trans('users.registration.username_already_taken')));
     }
     if (!$this->checkEmail($user->getEmail())) {
         $return = true;
         $form->get('email')->addError(new FormError($this->translator->trans('users.registration.email_already_taken')));
     }
     if ($return) {
         return false;
     }
     $user->setSalt(uniqid('', true));
     $password = $this->encoder->encodePassword($user, $user->getPlainPassword());
     $user->setPassword($password);
     $user->addRole('ROLE_USER');
     $user->enable(false);
     $this->em->persist($user);
     $this->em->flush();
     $this->activationLinkManager->createActivationLink($user);
     $this->activationLinkManager->sendValidationMail($user);
     return true;
 }
开发者ID:Medievistes,项目名称:application,代码行数:30,代码来源:UserManager.php

示例14: Load

 public function Load()
 {
     parent::$PAGE_TITLE = __(ERROR_USER_BANNED) . " - " . __(SITE_NAME);
     parent::$PAGE_META_ROBOTS = "noindex, nofollow";
     $can_use_captacha = true;
     if (WspBannedVisitors::isBannedIp($this->getRemoteIP())) {
         $last_access = new DateTime(WspBannedVisitors::getBannedIpLastAccess($this->getRemoteIP()));
         $duration = WspBannedVisitors::getBannedIpDuration($this->getRemoteIP());
         $dte_ban = $last_access->modify("+" . $duration . " seconds");
         if ($dte_ban > new DateTime()) {
             $can_use_captacha = false;
         }
     }
     $obj_error_msg = new Object(new Picture("wsp/img/warning.png", 48, 48, 0, "absmidlle"), "<br/><br/>");
     $obj_error_msg->add(new Label(__(ERROR_USER_BANNED_MSG_1), true), "<br/>");
     if ($can_use_captacha) {
         $obj_error_msg->add(new Label(__(ERROR_USER_BANNED_MSG_2), true), "<br/><br/>");
         $this->captcha_error_obj = new Object();
         $form = new Form($this);
         $this->captcha = new Captcha($form);
         $this->captcha->setFocus();
         $unblock_btn = new Button($form);
         $unblock_btn->setValue(__(ERROR_USER_BUTTON))->onClick("onClickUnblock");
         $form->setContent(new Object($this->captcha, "<br/>", $unblock_btn));
         $obj_error_msg->add($this->captcha_error_obj, "<br/>", $form);
     }
     $obj_error_msg->add("<br/><br/>", __(MAIN_PAGE_GO_BACK), new Link(BASE_URL, Link::TARGET_NONE, __(SITE_NAME)));
     $this->render = new ErrorTemplate($obj_error_msg, __(ERROR_USER_BANNED));
 }
开发者ID:kxopa,项目名称:WebSite-PHP,代码行数:29,代码来源:error-user-ban.php

示例15: run

 public function run($static = false)
 {
     $form = new Form();
     $form->post('login')->val('blank')->post('password')->val('blank');
     if (!$form->submit()) {
         // Error
         $this->_error($static);
         return false;
     }
     $data = $form->fetch();
     $login = $data['login'];
     $password = Hash::create('sha256', $data['password'], PASS_HASH_KEY);
     $query = "SELECT userid, login, role FROM user WHERE login = :login AND password = :password";
     if (!($result = $this->db->select($query, array(':login' => $login, ':password' => $password)))) {
         $this->_error($static);
         return false;
     }
     Session::init();
     Session::set('userid', $result[0]['userid']);
     Session::set('login', $result[0]['login']);
     Session::set('role', $result[0]['role']);
     Session::set('loggedIn', true);
     if ($static) {
         header('location:' . URL . 'dashboard');
     }
     echo json_encode('success');
 }
开发者ID:spelgrift,项目名称:imageman,代码行数:27,代码来源:login_model.php


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