本文整理汇总了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);
}
示例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;
}
示例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;
}
示例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;
}
}
}
示例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;
}
示例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();
}
}
示例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;
}
示例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;
}
示例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()));
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
示例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');
}