public function create($model = null, $options = array()) { if (!empty($options['inputDefaults'])){ extract($options['inputDefaults']); $class = (!empty($class))? 'form-control '.$class:'form-control'; $before = (!empty($before))? '<div class="form-group">'.$before : '<div class="form-group">'; $between = (!empty($between))? '<div class="col-sm-10"> '.$between:'<div class="col-sm-10">'; $after = (!empty($after))? '</div></div> '.$after:'</div></div>'; if ((!empty($label)) and is_array($label)) { $label['class'] = (!empty($label['class']))? 'control-label col-sm-2 '.$label: 'control-label col-sm-2'; } else if (!empty($label)) { $label['text'] = $label; $label['class'] = 'control-label col-sm-2'; } } else { $class = 'form-control'; $before = '<div class="form-group">'; $between = '<div class="col-sm-10">'; $after = '</div></div>'; $label['class'] = 'control-label col-sm-2 '; } $options['class'] = (empty($options['class']))?'form-horizontal':'form-horizontal '.$options['class']; $options['role'] = (empty($options['role']))?'form':'form '.$options['role']; $options['inputDefaults']['class'] = $class; $options['inputDefaults']['before'] = $before; $options['inputDefaults']['between'] = $between; $options['inputDefaults']['after'] = $after; $options['inputDefaults']['label'] = $label; $options['inputDefaults']['div']=false; return parent::create($model, $options); }
/** * フォーム開始タグを作成する * * @param type $model * @param type $options * @return string */ public function create($model = null, $options = array()) { if (!is_null($model) && !$this->_model instanceof $model) { $this->_model = ClassRegistry::init($model); } return parent::create($model, $options); }
/** * Overwrite FormHelper::create() * * Added: Automatically specifies inputDefaults depending on form class * * Returns an HTML FORM element. * * ### Options: * * - `type` Form method defaults to POST * - `action` The controller action the form submits to, (optional). * - `url` The URL the form submits to. Can be a string or a URL array. If you use 'url' * you should leave 'action' undefined. * - `default` Allows for the creation of Ajax forms. Set this to false to prevent the default event handler. * Will create an onsubmit attribute if it doesn't not exist. If it does, default action suppression * will be appended. * - `onsubmit` Used in conjunction with 'default' to create ajax forms. * - `inputDefaults` set the default $options for FormHelper::input(). Any options that would * be set when using FormHelper::input() can be set here. Options set with `inputDefaults` * can be overridden when calling input() * - `encoding` Set the accept-charset encoding for the form. Defaults to `Configure::read('App.encoding')` * * @param mixed $model The model name for which the form is being defined. Should * include the plugin name for plugin models. e.g. `ContactManager.Contact`. * If an array is passed and $options argument is empty, the array will be used as options. * If `false` no model is used. * @param array $options An array of html attributes and options. * @return string An formatted opening FORM tag. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#options-for-create */ public function create($model = null, $options = array()) { if ($bootstrapVersion = Configure::read('BoostCake.bootstrap_version')) { if (is_array($model) && empty($options)) { $options = $model; $model = null; } $bootstrapClasses = array_keys(Configure::read("BoostCake.inputDefaults.{$bootstrapVersion}")); if (!isset($options['class'])) { $formClasses = array('default'); } else { $formClasses = explode(' ', $options['class']); } $formClasses = array_reverse($formClasses); $formClasses[] = 'default'; foreach ($formClasses as $formClass) { if (in_array($formClass, $bootstrapClasses)) { $class = $formClass; break; } } if ($inputDefaults = Configure::read("BoostCake.inputDefaults.{$bootstrapVersion}.{$class}")) { $options = Hash::merge(array('inputDefaults' => $inputDefaults), $options); } } $html = parent::create($model, $options); return $html; }
public function create($model = null, $options = array()) { if (empty($options['class'])) { $options['class'] = 'well'; } return parent::create($model, $options); }
/** * Adds the class `form-horizontal` as its required by bootstrap * */ public function create($model = null, $options = array()) { if (is_array($model) && empty($options)) { $options = $model; $model = null; } $defaults = array('class' => 'form-horizontal'); $options = Set::merge($defaults, $options); return parent::create($model, $options); }
public function create($model = null, $options = array()) { $defaultOptions = array('inputDefaults' => array('div' => array('class' => 'form-group'), 'label' => array('class' => 'col-lg-2 control-label'), 'between' => '<div class="col-lg-10">', 'seperator' => '</div>', 'after' => '</div>', 'class' => 'form-control'), 'class' => 'form-horizontal', 'role' => 'form'); if (!empty($options['inputDefaults'])) { $options = array_merge($defaultOptions['inputDefaults'], $options['inputDefaults']); } else { $options = array_merge($defaultOptions, $options); } return parent::create($model, $options); }
public function create($model = null, $options = array()) { $defaultOptions = array('class' => 'form-horizontal', 'inputDefaults' => array('format' => array('before', 'label', 'between', 'input', 'error', 'after'), 'div' => 'control-group', 'label' => array('class' => 'control-label'), 'between' => '<div class="controls">', 'after' => '</div>', 'error' => array('attributes' => array('wrap' => 'span', 'class' => 'help-inline')))); if (!empty($options['inputDefaults'])) { $options = array_merge($defaultOptions['inputDefaults'], $options['inputDefaults']); } else { $options = array_merge($defaultOptions, $options); } return parent::create($model, $options); }
/** * Makes sure language prefix is always set * @param null $model * @param array $options * @return string */ public function create($model = null, $options = array()) { if (!isset($options['url']['language']) && isset($this->params['language']) && !is_string($options['url'])) { if (!isset($options['url'])) { $options['url'] = array(); } $options['url']['language'] = $this->params['language']; } return parent::create($model, $options); }
public function create($model = null, $options = array()) { $form = parent::create($model, $options); if (isset($this->params['named']['backTo'])) { $form .= $this->hidden('params.backTo', array('value' => $this->params['named']['backTo'])); } if (isset($this->data['params']['backTo'])) { $form .= $this->hidden('params.backTo', array('value' => $this->data['params']['backTo'])); } return $form; }
public function create($model = null, $options = array()) { //$mainLabelOptions = array('class' => 'col-sm-2 control-label'); $defaultOptions = array('inputDefaults' => array('div' => array('class' => 'form-group'), 'format' => array('before', 'label', 'between', 'input', 'error', 'after'), 'between' => '<span class="col-sm-6">', 'error' => array('attributes' => array('wrap' => 'span', 'class' => 'text-danger margin-left-5 number')))); if (!empty($options['inputDefaults'])) { $options = array_merge($defaultOptions['inputDefaults'], $options['inputDefaults']); } else { $options = array_merge($defaultOptions, $options); } return parent::create($model, $options); }
/** * adds the default class 'form-horizontal to the <form> * */ public function create($model = null, $options = array()) { if (isset($this->request['language']) && !empty($options['url'])) { if (is_array($options['url'])) { $options['url']['language'] = Configure::read('Config.langCode'); } else { $options['url'] = '/' . $this->request['language'] . $options['url']; } } $class = array('class' => 'form-horizontal'); $options = array_merge($class, $options); return parent::create($model, $options); }
/** * Add a form key after two seconds to help secure the form. */ public function create($model = null, $options = array()) { if ($options['secure'] === true) { // this piece is copied from the parent function, because we need the id earlier if (!isset($options['id'])) { $domId = isset($options['action']) ? $options['action'] : $this->request['action']; $options['id'] = $this->domId($domId . 'Form'); } // hash the form action to write into settings, as a form that must be checked $settingValue = 'c' . Security::hash($this->url($this->_getAction($options)), 'md5', Configure::read('Security.salt')); // this is how we know which forms have to be checked on the catch side if (defined('__APP_SECURE_FORMS')) { // read settings $values = unserialize(__APP_SECURE_FORMS); $saveNewForm = false; if (!in_array($settingValue, $values['form'])) { // add to settings if it isn't in there already array_push($values['form'], $settingValue); $value = ''; foreach ($values['form'] as $formId) { $value .= 'form[] = ' . $formId . PHP_EOL; } $saveNewForm = true; } } else { // add setting value $value = 'form[] = ' . $settingValue; $saveNewForm = true; } if (!empty($saveNewForm)) { $Setting = ClassRegistry::init('Setting'); $data['Setting']['type'] = 'App'; $data['Setting']['name'] = 'SECURE_FORMS'; $data['Setting']['value'] = $value; $Setting->add($data); } // this code is extremely slow, it can cause pages to take two minutes to load $context = stream_context_create(array('http' => array('header' => 'Connection: close\\r\\n'))); $json = json_decode(file_get_contents('http://' . $_SERVER['HTTP_HOST'] . '/forms/forms/secure.json', false, $context)); echo '<script type="text/javascript"> jQuery(document).ready(function() { var timeOut = window.setTimeout(function() { jQuery("#' . $options['id'] . '").prepend("<input type=\\"hidden\\" name=\\"data[FormKey][id]\\" value=\\"' . $json->key . '\\" />"); }, 10000); }); </script>'; } if ($options['action'] === null && $options['url'] === null) { // zuha over writes the the action if it isn't specified to preserve the prefix and query string (cake < 2.4 did for us) $options['url'] = $_SERVER['REQUEST_URI']; } return parent::create($model, $options); }
function create($model = null, $options = array()) { $options = array_merge(array('fieldset' => true), $options); if ($options['fieldset'] !== false) { $append = $this->fieldset($options['fieldset']); } if (isset($options['class'])) { $options['class'] .= ' uniForm'; } else { $options['class'] = 'uniForm'; } unset($options['fieldset']); return parent::create($model, $options) . $append; }
/** * Create * * @param $model string * @param $options array * @return string */ public function create($model = null, $options = array()) { if (empty($options['class'])) { $options['class'] = 'well'; } $modelKey = $this->model(); $Model = ClassRegistry::init($modelKey); if (!empty($Model->displayFieldTypes[$modelKey])) { if (in_array('image', $Model->displayFieldTypes[$modelKey]) || in_array('file', $Model->displayFieldTypes[$modelKey])) { $type_val = array('type' => 'file'); $options = array_merge($type_val, $options); } } return parent::create($model, $options); }
public function create($model, $options = array()) { //$this->_inputDefaults = $this->_myInputDefaults; $defaults = $this->_defaults; $defaults['inputDefaults'] = $this->_myInputDefaults; if (is_array($options['inputDefaults'])) { foreach ($options['inputDefaults'] as $k => $v) { $defaults['inputDefaults'][$k] = $v; } unset($options['inputDefaults']); } $options = Set::merge($defaults, $options); $this->_model = $model; return parent::create($model, $options); }
/** * Returns an HTML FORM element. * * ### Options: * * - `type` Form method defaults to POST * - `action` The controller action the form submits to, (optional). * - `url` The URL the form submits to. Can be a string or a URL array. If you use 'url' * you should leave 'action' undefined. * - `default` Allows for the creation of Ajax forms. Set this to false to prevent the default event handler. * Will create an onsubmit attribute if it doesn't not exist. If it does, default action suppression * will be appended. * - `onsubmit` Used in conjunction with 'default' to create ajax forms. * - `inputDefaults` set the default $options for FormHelper::input(). Any options that would * be set when using FormHelper::input() can be set here. Options set with `inputDefaults` * can be overridden when calling input() * - `encoding` Set the accept-charset encoding for the form. Defaults to `Configure::read('App.encoding')` * * @param mixed $model The model name for which the form is being defined. Should * include the plugin name for plugin models. e.g. `ContactManager.Contact`. * If an array is passed and $options argument is empty, the array will be used as options. * If `false` no model is used. * @param array $options An array of html attributes and options. * @return string An formatted opening FORM tag. */ public function create($model = null, $options = array()) { if (!isset($options['role'])) { $options['role'] = 'form'; } if (isset($options['cherry'])) { $this->cherry = $options['cherry']; unset($options['cherry']); } else { $this->cherry = false; } if ($this->cherry !== true && $this->cherry !== false && !isset($options['class'])) { $options['class'] = $this->cherry; } return parent::create($model, $options); }
public function create($model, $options = array()) { $options['class'] = isset($options['class']) && $options['class'] ? $options['class'] : 'form-horizontal'; $options['inputDefaults'] = isset($options['inputDefaults']) && $options['inputDefaults'] ? $options['inputDefaults'] : array('div' => 'form-group', 'class' => 'form-control', 'label' => array('class' => 'col-md-3 control-label'), 'between' => '<div class="col-md-9">', 'after' => '</div>'); // Fix validation errors translation foreach ($this->validationErrors as $_model => $fields) { if (is_array($fields)) { foreach ($fields as $field => $messages) { foreach ($messages as $i => $msg) { $this->validationErrors[$_model][$field][$i] = __($msg); } } } } return '<div class="portlet-body form tabbable-bordered">' . parent::create($model, $options); }
public function create($model = null, $options = array()) { $defaultOptions = array('inputDefaults' => array('div' => array('class' => 'form-group'), 'label' => array('class' => 'col-lg-2 control-label'), 'between' => '<div class="col-lg-10">', 'seperator' => '</div>', 'after' => '</div>', 'class' => 'form-control'), 'class' => 'form-horizontal', 'role' => 'form', 'novalidate' => false); if (isset($options['error']) && $options['error'] == false) { $defaultOptions['inputDefaults']['error'] = false; unset($options['error']); } if (isset($options['bootstrap']) && $options['bootstrap'] == false) { $defaultOptions = array('class' => 'form-horizontal', 'role' => 'form', 'novalidate' => false); unset($options['bootstrap']); } if (!empty($options['inputDefaults'])) { $options = array_merge($defaultOptions['inputDefaults'], $options['inputDefaults']); } else { $options = array_merge($defaultOptions, $options); } return parent::create($model, $options); }
/** * Create a Twitter Bootstrap like form. * * @param $model The model corresponding to the form * @param $options Options to customize the form * @return The HTML tags corresponding to the openning of the form * * Extra options: * - ga_type : string Form type GA_NAVBAR|GA_HORIZONTAL|GA_INLINE|GA_SEARCH */ public function create($model = null, $options = []) { $this->formType = $this->_extractOption('ga_type', $options, null); unset($options['ga_type']); if (!empty($this->formType) && in_array($this->formType, array_keys($this->formTypes))) { $options = $this->addClass($options, $this->formTypes[$this->formType]); } $inputDefaults = null; if ($this->formType === GA_HORIZONTAL) { $inputDefaults = ['div' => ['class' => GA_CONTROL_GROUP]]; } $options['inputDefaults'] = $this->_extractOption('inputDefaults', $options, $inputDefaults); if (in_array($this->formType, [GA_NAVBAR, GA_INLINE, GA_SEARCH])) { if (isset($options['inputDefaults']['div'])) { $options['inputDefaults']['div'] = false; } } return parent::create($model, $options) . PHP_EOL; }
/** * new options * - col range 1..12 (for horizontal form), by default 3. * * (non-PHPdoc) * @see FormHelper::create() */ public function create($model = null, $options = array()) { $default = array('role' => 'form', 'col' => 3); if (!empty($options['col'])) { $default['col'] = $options['col']; unset($options['col']); } $this->colNum = $default['col']; $formClasses = preg_split("/[\\s]+/", $this->_extractOption('class', $options), null, PREG_SPLIT_NO_EMPTY); if (in_array(self::FORM_HORIZONTAL, $formClasses)) { $default['inputDefaults'] = array('format' => array('before', 'label', 'between', 'input', 'error', 'after'), 'div' => array('class' => self::CLASS_DIV), 'class' => self::CLASS_INPUT, 'label' => array('class' => sprintf('col-lg-%d %s', $this->colNum, self::CLASS_LABEL)), 'between' => sprintf('<div class="col-lg-%d">', 12 - $this->colNum), 'after' => '</div>', 'error' => array('attributes' => array('wrap' => 'p', 'class' => 'help-block'))); self::$FORM_TYPE = self::FORM_HORIZONTAL; } elseif (in_array(self::FORM_INLINE, $formClasses)) { $default['inputDefaults'] = array('format' => array('before', 'label', 'between', 'input', 'error', 'after'), 'div' => array('class' => self::CLASS_DIV), 'class' => self::CLASS_INPUT, 'label' => array('class' => 'sr-only'), 'error' => false); self::$FORM_TYPE = self::FORM_INLINE; } else { $default['inputDefaults'] = array('format' => array('before', 'label', 'between', 'input', 'error', 'after'), 'div' => array('class' => self::CLASS_DIV), 'class' => self::CLASS_INPUT, 'label' => array('class' => self::CLASS_LABEL), 'error' => array('attributes' => array('wrap' => 'p', 'class' => 'help-block'))); self::$FORM_TYPE = self::FORM_DEFAULT; } $options = Hash::merge($default, $options); return parent::create($model, $options); }
/** * create method * * Default the form to the current url. add a hidden field for the referer * * @param mixed $model * @param array $options * @return void * @access public */ public function create($model = null, $options = array()) { if (!isset($options['url']) && !isset($options['action'])) { $options['url'] = '/' . ltrim($this->params['url']['url'], '/'); } if (!empty($options['url'])) { $getParams = array_diff_key($this->params['url'], array('ext' => true, 'url' => true)); if ($getParams) { if (is_string($options['url'])) { $options['url'] .= '?' . http_build_query($getParams); } else { $options['url']['?'] = $getParams; } } } $return = parent::create($model, $options); if (!empty($options['noReferer'])) { return $return; } if (!empty($this->data['App']['referer'])) { $referer = $this->data['App']['referer']; } else { $referer = $this->Session->read('referer'); if (!$referer) { $referer = AppController::referer('/', true); if (Router::normalize($referer) == Router::normalize(array('admin' => false, 'controller' => 'users', 'action' => 'login'))) { $referer = '/'; } } } $referer = $this->hidden('App.referer', array('default' => $referer)); if (strpos('fieldset', $return)) { return preg_replace('#</fieldset>#', $referer . '</fieldset>', $return); } return $return . '<div style="display:none;">' . $referer . '</div>'; }
/** * create * フック用にラッピング * * @param array $model * @param array $options * @return string * @access public */ function create($model = null, $options = array()) { $options = $this->executeHook('beforeFormCreate', $model, $options); $out = parent::create($model, $options); return $this->executeHook('afterFormCreate', $out); }
/** * Redefine el metodo padre para aceptar configuraciones globales de forms, definidas en * bootstrap.php o por ej. en beforeRender de helper de app. * Configs. disponibles: * - Form.formDefaults * - Form.inputDefaults * * TODO: configs separadas por tipo de form * * @param mixed $model * @param array $options An array of html attributes and options. * @return string An formatted opening FORM tag. */ public function create($model = null, $options = array()) { $this->_processConfig($options); $optionsForCreate = Hash::merge($this->formOptions, array('inputDefaults' => $this->inputOptions)); unset($optionsForCreate['custom'], $optionsForCreate['inputDefaults']); return parent::create($model, $optionsForCreate); }
<?php FormHelper::create('loginForm'); FormHelper::input('email', "E-mail", Request::post('email'), array('placeholder' => 'Digite o seu e-mail', 'style' => 'max-width:400px', 'validation' => array('regex' => FormHelper::EMAIL, 'message' => 'Digite um <strong>E-mail</strong> válido.'))); FormHelper::password('password', "Senha", Request::post('password'), array('placeholder' => 'Digite o sua senha', 'style' => 'max-width:400px;', 'validation' => array('regex' => FormHelper::NOT_EMPTY, 'message' => 'Digite uma <strong>Senha</strong> para logar.'))); ?> <br/><?php FormHelper::startGroup(); FormHelper::submitAjax("Enviar", "auth", array('class' => 'button')); FormHelper::endGroup(); FormHelper::end();
public function create($model = null, $options = array()) { $optionsDefault = array(); $options = array_merge($optionsDefault, $options); return parent::create($model, $options); }
/** * Starts a new form with input defaults. * * @param string $model * @param array $options * @return string */ public function create($model = null, $options = []) { $defaults = ['inputDefaults' => ['div' => ['class' => 'form-group'], 'label' => ['class' => 'control-label'], 'class' => 'form-control', 'error' => ['attributes' => ['wrap' => 'p', 'class' => 'text-danger']]], 'class' => null, 'role' => 'form']; $options = Hash::merge($defaults, $options); return parent::create($model, $options); }
?> <section class="content"> <?php ErrorHandler::displayErrors(); ?> <div> <div class="notice">Note: Password is automatically set as the combination of user's first name and last four digits of their phone number, all lowercase.</div> <?php //error could be set elsewhere in the code, so we need retrieve it after the checks, if any //in this case, we are checking for the usernam, if it is already in the database $dataErrors = isset($validator) ? $validator->getErrors() : array(); $form = new FormHelper($data, $dataErrors); //id is important, they should be unique $form->create(array('class' => array('generic', 'addForm'), 'name' => 'addNewUserForm', 'method' => 'post', 'action' => BASE_DIR . '/admin/addUser.php')); $form->input(array('class' => 'formRow', 'input' => array('type' => 'select', 'selected' => $userType, 'id' => 'userGroup', 'options' => array('admin' => 'Administrator', 'rmhstaff' => 'RMH Staff Approver', 'socialworker' => 'Social Worker')), 'label' => array('value' => 'User Category'))); $form->input(array('class' => 'formRow', 'input' => array('id' => 'title'), 'label' => array('value' => 'Title'))); $form->input(array('input' => array('id' => 'fname'), 'label' => array('value' => 'First Name'))); $form->input(array('input' => array('id' => 'lname'), 'label' => array('value' => 'Last Name'))); $form->input(array('input' => array('id' => 'phone', 'type' => 'tel'), 'label' => array('value' => 'Phone'))); $form->input(array('input' => array('id' => 'username'), 'label' => array('value' => 'Username'))); $form->input(array('class' => 'formRow', 'input' => array('id' => 'email', 'type' => 'email'), 'label' => array('value' => 'Email'))); if (isset($userType) && $userType == 'socialworker') { $form->input(array('input' => array('id' => 'hospital'), 'label' => array('value' => 'Hospital Affiliation'))); $form->input(array('input' => array('id' => 'notify', 'selected' => 'yes', 'type' => 'radio', 'options' => array('yes' => 'Yes', 'no' => 'No')), 'label' => array('value' => 'Email Notification'))); } $form->button(); $form->generate(); ?> </div>
public function create($model = null, $options = array()) { $options += array('class' => 'custom', 'role' => 'form', 'novalidate' => true); return parent::create($model, $options); }
public function create($model = null, $options = array()) { $class = explode(' ', $this->_extractOption('class', $options)); $inputDefaults = $this->_extractOption('inputDefaults', $options, array()); if (in_array(self::FORM_SEARCH, $class) || in_array(self::FORM_INLINE, $class)) { $options['inputDefaults'] = Set::merge($inputDefaults, array('div' => false, 'label' => false)); } elseif (in_array(self::FORM_HORIZONTAL, $class)) { $options['inputDefaults'] = Set::merge($inputDefaults, array('div' => self::CLASS_GROUP)); } else { $options['inputDefaults'] = Set::merge($inputDefaults, array('div' => null)); } return parent::create($model, $options); }
public function create($model = null, $options = array()) { $defaultOptions = array('inputDefaults' => array('div' => array('class' => 'form-group'), 'label' => false, 'class' => 'form-control')); $options = array_merge($defaultOptions, $options); return parent::create($model, $options); }