本文整理汇总了PHP中Fieldset类的典型用法代码示例。如果您正苦于以下问题:PHP Fieldset类的具体用法?PHP Fieldset怎么用?PHP Fieldset使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Fieldset类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
public function index()
{
$user = System::getUser();
$form = new Form('form-profile');
$form->setAttribute('data-noajax', 'true');
$form->binding = $user;
$fieldset = new Fieldset(System::getLanguage()->_('General'));
$firstname = new Text('firstname', System::getLanguage()->_('Firstname'));
$firstname->binding = new Databinding('firstname');
$lastname = new Text('lastname', System::getLanguage()->_('Lastname'));
$lastname->binding = new Databinding('lastname');
$email = new Text('email', System::getLanguage()->_('EMail'), true);
$email->binding = new Databinding('email');
$email->blacklist = $this->getListOfMailAdresses($user);
$email->error_msg[4] = System::getLanguage()->_('ErrorMailAdressAlreadyExists');
$language = new Radiobox('lang', System::getLanguage()->_('Language'), L10N::getLanguages());
$language->binding = new Databinding('lang');
$fieldset->addElements($firstname, $lastname, $email, $language);
$form->addElements($fieldset);
$fieldset = new Fieldset(System::getLanguage()->_('Password'));
$password = new Password('password', System::getLanguage()->_('Password'));
$password->minlength = PASSWORD_MIN_LENGTH;
$password->binding = new Databinding('password');
$password2 = new Password('password2', System::getLanguage()->_('ReenterPassword'));
$fieldset->addElements($password, $password2);
$form->addElements($fieldset);
$fieldset = new Fieldset(System::getLanguage()->_('Settings'));
$quota = new Text('quota', System::getLanguage()->_('Quota'));
if ($user->quota > 0) {
$quota->value = System::getLanguage()->_('QuotaAvailabe', Utils::formatBytes($user->getFreeSpace()), Utils::formatBytes($user->quota));
} else {
$quota->value = System::getLanguage()->_('Unlimited');
}
$quota->readonly = true;
$fieldset->addElements($quota);
$form->addElements($fieldset);
if (Utils::getPOST('submit', false) !== false) {
if (!empty($password->value) && $password->value != $password2->value) {
$password2->error = System::getLanguage()->_('ErrorInvalidPasswords');
} else {
if ($form->validate()) {
$form->save();
System::getUser()->save();
System::getSession()->setData('successMsg', System::getLanguage()->_('ProfileUpdated'));
System::forwardToRoute(Router::getInstance()->build('ProfileController', 'index'));
exit;
}
}
} else {
$form->fill();
}
$form->setSubmit(new Button(System::getLanguage()->_('Save'), 'floppy-disk'));
$smarty = new Template();
$smarty->assign('title', System::getLanguage()->_('MyProfile'));
$smarty->assign('heading', System::getLanguage()->_('MyProfile'));
$smarty->assign('form', $form->__toString());
$smarty->display('form.tpl');
}
示例2: add_elements
function add_elements($elements)
{
$args['class'] = 'well';
for ($i = 0; $i < $this->group_count; $i++) {
$fieldset = new Fieldset($this, $i, $args);
$fieldset->add_elements($elements);
$this->elements[$i] = $fieldset;
}
}
示例3: set_fields
/**
* Set a Model's properties as fields on a Fieldset, which will be created with the Model's
* classname if none is provided.
*
* @param string
* @param Fieldset|null
* @return Fieldset
*/
public static function set_fields($class, $fieldset = null)
{
$properties = $class::properties();
if (is_null($fieldset)) {
$fieldset = \Fieldset::instance($class);
if (!$fieldset) {
$fieldset = \Fieldset::factory($class);
}
}
foreach ($properties as $p => $settings) {
$field = $fieldset->add($p, !empty($settings['label']) ? $settings['label'] : $p);
if (empty($settings['validation'])) {
continue;
} else {
foreach ($settings['validation'] as $rule => $args) {
if (is_int($rule) and is_string($args)) {
$args = array($args);
} else {
array_unshift($args, $rule);
}
call_user_func_array(array($field, 'add_rule'), $args);
}
}
}
return $fieldset;
}
示例4: action_regist
/**
* ユーザ登録
*
* @access public
* @return View
*/
public function action_regist()
{
$view = View::forge('admin/regist');
$form = Fieldset::forge();
$form->form()->set_attribute('class', 'form form-horizontal');
$form->add('username', 'ログインID', array('class' => 'form-control'))->add_rule('required')->add_rule('min_length', 3)->add_rule('max_length', 50);
$form->add('password', 'パスワード', array('class' => 'form-control'))->add_rule('required')->add_rule('min_length', 3)->add_rule('max_length', 20);
$form->add('email', 'Eメール', array('class' => 'form-control'))->add_rule('required')->add_rule('valid_email');
$form->add('submit', '', array('type' => 'submit', 'value' => '登録', 'class' => 'btn btn-primary'));
if (\Input::post()) {
$val = $form->validation();
if ($val->run()) {
$result = \Auth::create_user(\Input::post('username'), \Input::post('password'), \Input::post('email'), 1, array());
if ($result) {
$view->set_global('massage', array('css' => 'success', 'content' => '登録に成功しました。'));
} else {
$form->repopulate();
$view->set_global('massage', array('css' => 'danger', 'content' => '既に登録済みの情報が使用されています。'));
}
} else {
$form->repopulate();
$view->set_global('errors', $val->error());
}
}
$form->build('/form/confirm');
$view->set_safe('form', $form);
return $view;
}
示例5: set_fields
/**
* Set a Model's properties as fields on a Fieldset, which will be created with the Model's
* classname if none is provided.
*
* @param string
* @param Fieldset|null
* @return Fieldset
*/
public static function set_fields($obj, $fieldset = null)
{
static $_generated = array();
$class = is_object($obj) ? get_class($obj) : $obj;
if (is_null($fieldset)) {
$fieldset = \Fieldset::instance($class);
if (!$fieldset) {
$fieldset = \Fieldset::factory($class);
}
}
!array_key_exists($class, $_generated) and $_generated[$class] = array();
if (in_array($fieldset, $_generated[$class], true)) {
return $fieldset;
}
$_generated[$class][] = $fieldset;
$fieldset->validation()->add_callable($obj);
$properties = is_object($obj) ? $obj->properties() : $class::properties();
foreach ($properties as $p => $settings) {
$field = $fieldset->add($p, !empty($settings['label']) ? $settings['label'] : $p);
if (empty($settings['validation'])) {
continue;
} else {
foreach ($settings['validation'] as $rule => $args) {
if (is_int($rule) and is_string($args)) {
$args = array($args);
} else {
array_unshift($args, $rule);
}
call_user_func_array(array($field, 'add_rule'), $args);
}
}
}
return $fieldset;
}
示例6: onFormInitialized
/**
* 2015-11-19
* @override
* @see \Df\Framework\Form\Element\Fieldset::onFormInitialized()
* @used-by \Df\Framework\Plugin\Data\Form\Element\AbstractElement::afterSetForm()
* @return void
*/
public function onFormInitialized()
{
parent::onFormInitialized();
$this->addClass('df-array');
// 2015-12-29
// Невидимая строка-шаблон.
df_hide($this->field('template', $this->itemFormElement()));
/** @var int $itemId */
$itemId = 0;
foreach ($this->v() as $key => $data) {
/** @var string|int $key */
/** @var string|array(string => mixed) $data */
/**
* 2016-07-30
* Раньше тут стоял код:
// 2015-12-30
// https://github.com/mage2pro/core/tree/b1f6809b7723d8426636bb892b852f408bdc5650/Framework/view/adminhtml/web/formElement/array/main.js#L131
if (\Df\Config\A::FAKE !== $key) {
$this->field($itemId++, $this->itemType(), null, $data);
}
* Теперь у нас ключ @see \Df\Config\A::FAKE удаляется в методе
* @see \Df\Config\Backend\ArrayT::processA()
* поэтому здесь его уже быть не должно.
*/
df_assert_ne(\Df\Config\A::FAKE, $key);
$this->field($itemId++, $this->itemFormElement(), null, $data);
}
df_fe_init($this, __CLASS__, df_fa(), [], 'array');
}
示例7: action_create
public function action_create()
{
$fieldset = Fieldset::forge()->add_model('Model_Post');
$form = $fieldset->form();
$form->add('submit', '', array('type' => 'submit', 'value' => 'Add New Post', 'class' => 'btn btn-large'));
if (Input::method() == 'POST') {
if ($fieldset->validation()->run() == true) {
$fields = $fieldset->validated();
$post = Model_Post::forge();
foreach ($fields as $key => $value) {
$post->{$key} = $value;
}
$post->dive_time = Model_Post::calc_diff_of_time($post->exit, $post->entry);
$post->creatures = Model_Creature::parseCreatures(Input::post('report'));
if ($post->save()) {
Session::set_flash('success', e('Added post #' . $post->id . '.'));
Response::redirect('admin/posts');
} else {
Session::set_flash('error', e('Could not save post.'));
}
} else {
Session::set_flash('error', $val->error());
}
}
$this->template->set_global('form', $form->build(), false);
$this->template->title = "Posts";
$this->template->content = View::forge('admin/posts/create');
}
示例8: get_form
private function get_form($type = 0)
{
$form = Fieldset::instance();
if (count($form->field()) > 0) {
return $form;
}
switch ($type) {
case SettingType::PASSWORD:
$form->add("mail_address_new", "新しいメールアドレス");
$form->add("mail_address_new_confirm", "新しいメールアドレス(確認)");
$form->add("password", "現在のパスワード")->add_rule("required");
$form->add("password_new", "新しいパスワード")->add_rule("required")->add_rule("min_length", 4)->add_rule("max_length", 30)->add_rule("valid_string", array("alpha", "numeric"));
$form->add("password_new_confirm", "新しいパスワード(確認)")->add_rule("required")->add_rule("match_field", "password_new");
break;
case SettingType::MAILADDRESS:
$form->add("mail_address_new", "新しいメールアドレス")->add_rule("required")->add_rule("valid_email");
$form->add("mail_address_new_confirm", "新しいメールアドレス(確認)");
$form->add("password", "現在のパスワード");
$form->add("password_new", "新しいパスワード");
$form->add("password_new_confirm", "新しいパスワード(確認)");
break;
default:
break;
}
return $form;
}
示例9: getRadioCheckbox
public function getRadioCheckbox($renderApi, $unit, $fieldId, $postRequestValue = null, $required = false)
{
$formField = new \Fieldset();
$listOptions = $this->listOptions->getListOptions($renderApi, $unit);
$inputName = strlen($renderApi->getFormValue($unit, 'inputName')) > 0 ? $renderApi->getFormValue($unit, 'inputName') . "[]" : $fieldId . "[]";
if ($listOptions->hasOptions()) {
$optionCount = 0;
$options = $listOptions->getOptions();
$optionsLength = count($options);
foreach ($options as $option) {
/* @var $option \Option */
$properties = $unit->getFormValues();
if ($properties["listType"] === \ListType::RADIO) {
$choiceField = new \RadioButtonField();
} elseif ($properties["listType"] === \ListType::CHECKBOX) {
$choiceField = new \CheckboxField();
}
$optionId = $fieldId . '_' . $optionCount;
$elementProperties = $choiceField->getElementProperties();
$elementProperties->addAttribute("value", $option->getValue());
$elementProperties->addAttribute("name", $inputName);
$elementProperties->addAttribute("id", $optionId);
// set required attribute for radio options or when there is only one checkbox
// don't set for multiple checkboxes to match server-side validation logic
if ($required && ($properties["listType"] === \ListType::RADIO || $optionsLength === 1)) {
$elementProperties->addAttribute("required", null);
}
$request = new Request();
$request->isPostRequest();
if (!$request->isPostRequest() && $option->isChecked() || !is_null($postRequestValue) && in_array($option->getValue(), $postRequestValue)) {
$elementProperties->addAttribute("checked", null);
}
$label = new \Label();
$label->add($choiceField);
$label->add(new \Span($option->getName()));
$labelProperties = $label->getElementProperties();
$labelProperties->addAttribute("for", $optionId);
$formField->add($label);
$optionCount++;
}
}
if ($this->formSubmit->isValid($renderApi, $unit) && !$this->isValidValue($unit, $postRequestValue)) {
$formField->add($this->getErrorMessage($unit, $postRequestValue));
$formField->getElementProperties()->addClass('vf__error');
}
return $formField;
}
示例10: createFieldset
public static function createFieldset()
{
$contact = self::forge();
$fieldset = Fieldset::forge();
$fieldset->add_model($contact);
$fieldset->add('email2', 'メールアドレス確認用')->add_rule('required')->add_rule('match_field', 'email');
return $fieldset;
}
示例11: setOptions
/**
* Set options for a fieldset. Accepted options are:
* - input_filter_spec: specification to be returned by getInputFilterSpecification
*
* @param array|Traversable $options
* @return Element|ElementInterface|FieldsetInterface
* @throws Exception\InvalidArgumentException
*/
public function setOptions($options)
{
parent::setOptions($options);
if (isset($options['input_filter_spec'])) {
$this->setInputFilterSpecification($options['input_filter_spec']);
}
return $this;
}
示例12: validate_registration
public static function validate_registration(Fieldset $form, $auth)
{
$form->field('password')->add_rule('match_value', $form->field('password2')->get_attribute('value'));
$val = $form->validation();
$val->set_message('required', 'The field :field is required');
$val->set_message('valid_email', 'The field :field must be an email address');
$val->set_message('match_value', 'The passwords must match');
if ($val->run()) {
$username = $form->field('username')->get_attribute('value');
$password = $form->field('password')->get_attribute('value');
$email = $form->field('email')->get_attribute('value');
try {
$user = $auth->create_user($username, $password, $email);
} catch (Exception $e) {
$error = $e->getMessage();
}
if (isset($user)) {
$auth->login($username, $password);
} else {
if (isset($error)) {
$li = $error;
} else {
$li = 'Something went wrong with creating the user!';
}
$errors = Html::ul(array($li));
return array('e_found' => true, 'errors' => $errors);
}
} else {
$errors = $val->show_errors();
return array('e_found' => true, 'errors' => $errors);
}
}
示例13: forge_form
public function forge_form()
{
$form = Fieldset::forge();
$form->add('name', '名前')->add_rule('trim')->add_rule('required')->add_rule('no_tab_and_newline')->add_rule('max_length', 50);
$form->add('email', 'メールアドレス')->add_rule('trim')->add_rule('required')->add_rule('no_tab_and_newline')->add_rule('max_length', 100)->add_rule('valid_email');
$form->add('comment', 'コメント', array('type' => 'textarea', 'cols' => 70, 'rows' => 6))->add_rule('required')->add_rule('max_length', 400);
$form->add('submit', '', array('type' => 'submit', 'value' => '確認'));
return $form;
}
示例14: createFieldset
/**
* ログイン用のFieldsetをレスポンスします
*
* @access public
* @return Fieldset fieldset
* @author shimma
*/
public function createFieldset()
{
$fieldset = Session::get_flash('login.fieldset');
if (!$fieldset) {
$fieldset = \Fieldset::forge('login');
$fieldset->add('email', 'Email')->add_rule('required')->add_rule('valid_email');
$fieldset->add('password', 'Password')->add_rule('required');
}
return $fieldset;
}
示例15: renderContent
protected function renderContent()
{
$this->initializeRendering();
$content = '';
$content .= $this->openTag('div', array('class' => 'ObjectPicker ' . implode(' ', $this->metadata['listenToEvents'])));
// render the an hidden input, as fallback empty post value:
foreach ($this->getChildren() as $child) {
$content .= $this->selfClosingTag('input', array('type' => 'hidden', 'value' => '', 'name' => $this->getControlName($child->getAttribute('name'))));
}
$content .= $this->renderMeta();
$content .= $this->renderObjects();
$content .= $this->closeTag('div');
if ($this->hasAttribute('template')) {
$fieldsetWidget = new Fieldset($this->view);
$fieldsetWidget->setAttribute('template', $this->getAttribute('template'))->setAttribute('icon-before', $this->getAttribute('icon-before'))->insert($this->view->literal($content));
return $fieldsetWidget;
}
return $content;
}