/** * ファイルインプットボックス出力 * 画像の場合は画像タグ、その他の場合はファイルへのリンク * そして削除用のチェックボックスを表示する * [カスタムオプション] * imgsize・・・画像のサイズを指定する * * @param string $fieldName * @param array $options * @return string * @access public */ function file($fieldName, $options = array()) { $linkOptions = $_options = array('imgsize' => 'midium', 'rel' => '', 'title' => ''); $options = $this->_initInputField($fieldName, Set::merge($_options, $options)); $linkOptions['imgsize'] = $options['imgsize']; $linkOptions['rel'] = $options['rel']; $linkOptions['title'] = $options['title']; unset($options['imgsize']); unset($options['rel']); unset($options['title']); $view =& ClassRegistry::getObject('view'); $_field = $view->entity(); $modelName = $_field[0]; $field = $_field[1]; if (ClassRegistry::isKeySet($modelName)) { $model =& ClassRegistry::getObject($modelName); } else { return; } $fileLinkTag = $this->fileLink($fieldName, $linkOptions); $fileTag = parent::file($fieldName, $options); $delCheckTag = parent::checkbox($modelName . '.' . $field . '_delete') . parent::label($modelName . '.' . $field . '_delete', '削除する'); $hiddenValue = $this->value($fieldName . '_'); $fileValue = $this->value($fieldName); if (is_array($fileValue) && empty($fileValue['tmp_name']) && $hiddenValue) { $hiddenTag = parent::hidden($modelName . '.' . $field . '_', array('value' => $hiddenValue)); } else { $hiddenTag = parent::hidden($modelName . '.' . $field . '_', array('value' => $this->value($fieldName))); } $out = $fileTag; if ($fileLinkTag) { $out .= ' ' . $delCheckTag . $hiddenTag . '<br />' . $fileLinkTag; } return '<div class="upload-file">' . $out . '</div>'; }
public function render() { if ($this->getValue()) { $file = Toolkit::i()->fileStorage->bucket($this->getBucketName())->getFile($this->getValue()); echo '<a target="_blank" href="' . $file->getFileUrl() . '">' . $this->getValue() . '</a>'; echo '<br />'; echo FormHelper::checkbox($this->getAlias() . '_delete', false, ['id' => $this->getAlias() . '_delete']); echo ' ' . FormHelper::labelFor($this->getAlias() . '_delete', 'Удалить'); } echo FormHelper::file($this->getAlias(), $this->getValue(), array('id' => 'field_' . $this->getAlias())); }
public function render() { if ($this->getValue()) { $file = Toolkit::i()->fileStorage->bucket($this->getBucketName())->getImage($this->getValue()); echo '<img src="' . $file->getThumbUrl(100) . '" alt="" />'; echo '<br />'; echo FormHelper::checkbox($this->getAlias() . '_delete', false, ['id' => $this->getAlias() . '_delete']); echo ' ' . FormHelper::labelFor($this->getAlias() . '_delete', 'Удалить'); } echo FormHelper::file($this->getAlias(), $this->getValue(), array('id' => 'field_' . $this->getAlias())); }
public function checkbox($fieldName, $options = array()) { $label = $this->_extractOption('label', $this->_Opts[$fieldName]); if (!is_array($label)) { $label = array('text' => $label); } $after = $this->_extractOption('after', $this->_Opts[$fieldName]); if ($this->_isHorizontal) { $label['text'] = $after; $label['class'] = null; } $label = $this->addClass($label, 'checkbox'); $text = $label['text']; unset($label['text']); $out = parent::checkbox($fieldName, $options) . $text; return $this->label($fieldName, $out, $label); }
public function checkbox($fieldName, $options, $before = false) { if ($before) { if ('checkbox' === $options['type']) { if (!$this->_extractOption('div', $options)) { $options['label'] = false; } else { $options['after'] = null; } } return $options; } else { $label = $this->_extractOption('label', $this->_Opts[$fieldName]); if (!is_array($label)) { $label = array('text' => $label); } $after = $this->_extractOption('after', $this->_Opts[$fieldName]); if ($this->_extractOption('div', $this->_Opts[$fieldName])) { $label['text'] = $after; $label['class'] = null; } $label = $this->addClass($label, 'checkbox'); $text = $label['text']; unset($label['text']); $out = parent::checkbox($fieldName, $options) . $text; return $this->label($fieldName, $out, $label); } }
public function checkbox($fieldName, $options = array()) { if ($options['class'] == 'form-control') { $options['class'] = false; } return parent::checkbox($fieldName, $options); }
echo $this->getModel()->fieldTitle('Password'); ?> </label> <div class="col-sm-10"> <?php echo FormHelper::password('Password'); ?> </div> </div> <div class="form-group"> <div class="controls"> <div class="col-sm-offset-2 col-sm-10 checkbox-group"> <label class="col-sm-10" for="field_RememberMe"> <?php echo FormHelper::checkbox('RememberMe'); ?> <?php echo $this->getModel()->fieldTitle('RememberMe'); ?> </label> </div> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <button class="btn btn-primary" type="submit"><?php echo $this->t('Basic', 'Enter'); ?> </button>
echo FormHelper::radios('alignment', array('' => 'Aucun', 'right' => 'Droite', 'center' => 'Centrer', 'left' => 'Gauche'), ''); ?> </div> <div class="<?php echo ++$i % 2 ? 'odd' : 'even'; ?> "> <label for="link">Lien</label> <?php echo FormHelper::text('href', '', array('size' => '100')); ?> <br /> <?php echo FormHelper::checkbox('target', '_blank', '_blank'); ?> Ouvrir dans une nouvelle fenêtre </div> </fieldset> <div> <input class="button" type="submit" value="Insérer dans l'éditeur"> ou <a class="cancel" href="<?php echo UrlComponent::path(array('action' => 'insertionIndex')); ?> ">Annuler</a> </div> </form>
public function testCheckbox() { $this->assertEqual(FormHelper::checkbox('name', 'value', null, array('class' => 'myClass')), '<input type="checkbox" name="name" class="myClass" value="value" id="name">'); $this->assertEqual(FormHelper::checkbox('name', 'value', 'value', array('class' => 'myClass')), '<input type="checkbox" name="name" class="myClass" value="value" id="name" checked="checked">'); $this->assertEqual(FormHelper::checkbox('name', $this->Model, 'obj', array('class' => 'myClass')), '<input type="checkbox" name="name" class="myClass" value="obj" id="name" checked="checked">'); }
public function testCheckbox() { $html = $this->object->checkbox('element', 'value', true, array('arbitrary' => 'arbitrary', 'class' => 'test-class')); $this->assertAttributes($html, array('class' => array('test-class', 'ccm-input-checkbox'), 'arbitrary' => 'arbitrary')); }
/** * displays a single checkbox - called for each */ public function _checkbox($id, $group = null, $options = array()) { $defaults = array('class' => 'checkboxToggle'); $options = am($defaults, $options); return $script . parent::checkbox($fieldName, $options); }
/** * Creates a checkbox input widget. * * Extends of FormHelper::checkbox() so get same options and params * * Prefer use this function and not BsFormHelper::input() to create checkbox - better results and automatically adapted to Twitter Bootstrap v3 * * ### New Options: * * - `inline` - choose if you want inline checkbox - 'false' by default, can take 2 values : 'inline' or 'true' * - `help` - Add a message under the checkbox to give more informations * Use this option in an array with the label * Example : input('foo', array( * 'label' => 'name', * 'help' => 'informations' * ) * ); * * ### Options by default for Twitter Bootstrap v3 * * - 'div' - Set to 'false' * - 'label' - Set to 'false' * - 'label' - Add a 'control-label' class and if the form is horizontal, put the label into the left column of it * * ### Options can be extends with no conflicts when the input is being created * * - 'class' * - 'label' - string and array * * ### In case of multiple checkboxes -> use the Bs3FormHelper::select() * * Some options are added * - 'help' - can be for each, always with an array in parameter * - 'hiddenField' - 'false' by default * * @param string $fieldName Name of a field, like this "Modelname.fieldname" * @param array $options Array of HTML attributes. * * @return string An HTML text input element. */ public function checkbox($fieldName, $options = array()) { $basicOptions = array('help' => false, 'state' => false, 'label' => Inflector::camelize($fieldName), 'label-class' => ''); $options = $this->__errorBootstrap($fieldName, $options); foreach ($basicOptions as $opt => $valueOpt) { if (isset($options[$opt])) { $basicOptions[$opt] = $options[$opt]; unset($options[$opt]); } } $checkbox = parent::checkbox($fieldName, $options); $checkbox .= $basicOptions['label'] !== false ? ' ' . $basicOptions['label'] : ''; $checkbox .= $basicOptions['help'] ? '<span class="help-block">' . $basicOptions['help'] . '</span>' : ''; $options['type'] = 'checkbox'; $label = array('text' => $checkbox); if (!empty($basicOptions['label-class'])) { $label['class'] = $basicOptions['label-class']; } return $this->__buildCheckboxBefore($basicOptions['state']) . $this->_inputLabel($fieldName, $label, $options) . $this->__buildCheckboxAfter($basicOptions['state']); }
} </style> <div class="content"> <div class="panel-default"> <?php global $db; $id = Request::get('ident'); if ($id) { $u = $db->getResult('user', '*', 'id=' . $id, true); } else { $u = array("name" => "", "email" => "", "active" => "", "id" => 0); } FormHelper::create('formUsuario'); FormHelper::input('name', "Nome", $u['name'], array('placeholder' => 'Digite o nome', 'style' => 'max-width:400px', 'validation' => array('regex' => FormHelper::NOT_EMPTY, 'message' => 'Preencha o <strong>Nome</strong>.'))); FormHelper::input('email', "E-mail", $u['email'], array('placeholder' => 'Digite o e-mail', 'style' => 'max-width:400px', 'validation' => array('regex' => FormHelper::EMAIL, 'message' => 'Digite um <strong>E-mail</strong> válido.'))); FormHelper::checkbox('active', "Ativo", $u['active']); // ligação many to many para user_module $options = array('Nenhum', 'Visualizar', 'Incluir', 'Editar', 'Excluir'); if ($id) { ?> <h4>Permissões</h4> <div class="form-group <?php echo $m['permission']; ?> _group"> <?php $modules = $db->query('select id,name,permission from module'); $levels = $db->query("select level from user_module where user_id=" . $u['id']); if (count($levels) == 0) { $levels = array(); foreach ($modules as $m) {
/** * Creates a checkbox input widget. * * Extends of FormHelper::checkbox() so get same options and params * * Prefer use this function and not BsFormHelper::input() to create checkbox - better results and automatically adapted to Twitter Bootstrap v3 * * ### New Options: * * - `inline` - choose if you want inline checkbox - 'false' by default, can take 2 values : 'inline' or 'true' * - `help` - Add a message under the checkbox to give more informations * Use this option in an array with the label * Example : input('foo', array( * 'label' => 'name', * 'help' => 'informations' * ) * ); * * ### Options by default for Twitter Bootstrap v3 * * - 'div' - Set to 'false' * - 'label' - Set to 'false' * - 'label' - Add a 'control-label' class and if the form is horizontal, put the label into the left column of it * * ### Options can be extends with no conflicts when the input is being created * * - 'class' * - 'label' - string and array * * ### In case of multiple checkboxes -> use the Bs3FormHelper::select() * * Some options are added * - 'help' - can be for each, always with an array in parameter * - 'hiddenField' - 'false' by default * * @param string $fieldName Name of a field, like this "Modelname.fieldname" * @param array $options Array of HTML attributes. * @return string An HTML text input element. */ public function checkbox($fieldName, $options = array()) { //----- [div] option if (!isset($options['div'])) { $options['div'] = false; } //----- [label] option if (!isset($options['label'])) { $options['label'] = false; } $out = ''; if ($this->_getFormType() == 'horizontal') { $out .= '<div class="form-group">'; $out .= '<div class="col-md-offset-' . $this->left . ' col-md-' . $this->right . '">'; } //----- [inline] option if (!(isset($options['inline']) && ($options['inline'] == 'inline' || $options['inline'] == true))) { $out .= '<div class="checkbox">'; $out .= '<label>'; } else { $out .= '<label class="checkbox-inline">'; } $out .= parent::checkbox($fieldName, $options); //----- [label] option if ($options['label'] != false) { // If options are array('label' => 'text') if (is_array($options['label'])) { $out .= ' ' . $options['label']['label']; } else { $out .= ' ' . $options['label']; } } else { $out .= ' ' . Inflector::camelize($fieldName); } $out .= '</label>'; //----- [help] option for multiple checkboxes ([label] is an array) if (is_array($options['label']) && isset($options['label']['help']) && !empty($options['label']['help'])) { $out .= '<span class="help-block">' . $options['label']['help'] . '</span>'; } //----- [inline] option if (!(isset($options['inline']) && ($options['inline'] == 'inline' || $options['inline'] == true))) { $out .= '</div>'; } $out .= SP; //----- [help] option for single checkbox if ($this->_getFormType() == 'horizontal') { if (isset($options['help']) && !empty($options['help'])) { $out .= '<span class="help-block">' . $options['help'] . '</span>'; } $out .= '</div></div>'; } return $out; }
/** * Displays a single checkbox - called for each * //FIXME * * @return string */ protected function _checkbox($id, $group = null, $options = array()) { $defaults = array('class' => 'checkbox-toggle checkboxToggle'); $options += $defaults; return $script . parent::checkbox($fieldName, $options); }
public function render() { $sName = $this->getAlias(); echo FormHelper::checkbox($sName, $this->getValue(), array('id' => 'field_' . $this->getAlias())); }