PageRenderTime 53ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/src/View/Helper/FormHelper.php

https://github.com/ceeram/cakephp
PHP | 2527 lines | 1352 code | 212 blank | 963 comment | 220 complexity | 18b5d20d6dbf1f9eb6109104389c8785 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 0.10.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\View\Helper;
  16. use Cake\Collection\Collection;
  17. use Cake\Core\Configure;
  18. use Cake\Core\Exception\Exception;
  19. use Cake\Form\Form;
  20. use Cake\ORM\Entity;
  21. use Cake\Routing\Router;
  22. use Cake\Utility\Hash;
  23. use Cake\Utility\Inflector;
  24. use Cake\Utility\Security;
  25. use Cake\View\Form\ArrayContext;
  26. use Cake\View\Form\ContextInterface;
  27. use Cake\View\Form\EntityContext;
  28. use Cake\View\Form\FormContext;
  29. use Cake\View\Form\NullContext;
  30. use Cake\View\Helper;
  31. use Cake\View\Helper\IdGeneratorTrait;
  32. use Cake\View\StringTemplateTrait;
  33. use Cake\View\View;
  34. use Cake\View\Widget\WidgetRegistry;
  35. use DateTime;
  36. use Traversable;
  37. /**
  38. * Form helper library.
  39. *
  40. * Automatic generation of HTML FORMs from given data.
  41. *
  42. * @property HtmlHelper $Html
  43. * @link http://book.cakephp.org/3.0/en/views/helpers/form.html
  44. */
  45. class FormHelper extends Helper
  46. {
  47. use IdGeneratorTrait;
  48. use StringTemplateTrait;
  49. /**
  50. * Other helpers used by FormHelper
  51. *
  52. * @var array
  53. */
  54. public $helpers = ['Url', 'Html'];
  55. /**
  56. * The various pickers that make up a datetime picker.
  57. *
  58. * @var array
  59. */
  60. protected $_datetimeParts = ['year', 'month', 'day', 'hour', 'minute', 'second', 'meridian'];
  61. /**
  62. * Special options used for datetime inputs.
  63. *
  64. * @var array
  65. */
  66. protected $_datetimeOptions = [
  67. 'interval', 'round', 'monthNames', 'minYear', 'maxYear',
  68. 'orderYear', 'timeFormat', 'second'
  69. ];
  70. /**
  71. * Default config for the helper.
  72. *
  73. * @var array
  74. */
  75. protected $_defaultConfig = [
  76. 'errorClass' => 'form-error',
  77. 'typeMap' => [
  78. 'string' => 'text', 'datetime' => 'datetime', 'boolean' => 'checkbox',
  79. 'timestamp' => 'datetime', 'text' => 'textarea', 'time' => 'time',
  80. 'date' => 'date', 'float' => 'number', 'integer' => 'number',
  81. 'decimal' => 'number', 'binary' => 'file', 'uuid' => 'string'
  82. ],
  83. 'templates' => [
  84. 'button' => '<button{{attrs}}>{{text}}</button>',
  85. 'checkbox' => '<input type="checkbox" name="{{name}}" value="{{value}}"{{attrs}}>',
  86. 'checkboxFormGroup' => '{{label}}',
  87. 'checkboxWrapper' => '<div class="checkbox">{{label}}</div>',
  88. 'dateWidget' => '{{year}}{{month}}{{day}}{{hour}}{{minute}}{{second}}{{meridian}}',
  89. 'error' => '<div class="error-message">{{content}}</div>',
  90. 'errorList' => '<ul>{{content}}</ul>',
  91. 'errorItem' => '<li>{{text}}</li>',
  92. 'file' => '<input type="file" name="{{name}}"{{attrs}}>',
  93. 'fieldset' => '<fieldset>{{content}}</fieldset>',
  94. 'formStart' => '<form{{attrs}}>',
  95. 'formEnd' => '</form>',
  96. 'formGroup' => '{{label}}{{input}}',
  97. 'hiddenBlock' => '<div style="display:none;">{{content}}</div>',
  98. 'input' => '<input type="{{type}}" name="{{name}}"{{attrs}}>',
  99. 'inputSubmit' => '<input type="{{type}}"{{attrs}}>',
  100. 'inputContainer' => '<div class="input {{type}}{{required}}">{{content}}</div>',
  101. 'inputContainerError' => '<div class="input {{type}}{{required}} error">{{content}}{{error}}</div>',
  102. 'label' => '<label{{attrs}}>{{text}}</label>',
  103. 'nestingLabel' => '{{hidden}}<label{{attrs}}>{{input}}{{text}}</label>',
  104. 'legend' => '<legend>{{text}}</legend>',
  105. 'option' => '<option value="{{value}}"{{attrs}}>{{text}}</option>',
  106. 'optgroup' => '<optgroup label="{{label}}"{{attrs}}>{{content}}</optgroup>',
  107. 'select' => '<select name="{{name}}"{{attrs}}>{{content}}</select>',
  108. 'selectMultiple' => '<select name="{{name}}[]" multiple="multiple"{{attrs}}>{{content}}</select>',
  109. 'radio' => '<input type="radio" name="{{name}}" value="{{value}}"{{attrs}}>',
  110. 'radioWrapper' => '{{label}}',
  111. 'textarea' => '<textarea name="{{name}}"{{attrs}}>{{value}}</textarea>',
  112. 'submitContainer' => '<div class="submit">{{content}}</div>',
  113. ]
  114. ];
  115. /**
  116. * Default widgets
  117. *
  118. * @var array
  119. */
  120. protected $_defaultWidgets = [
  121. 'button' => ['Cake\View\Widget\ButtonWidget'],
  122. 'checkbox' => ['Cake\View\Widget\CheckboxWidget'],
  123. 'file' => ['Cake\View\Widget\FileWidget'],
  124. 'label' => ['Cake\View\Widget\LabelWidget'],
  125. 'nestingLabel' => ['Cake\View\Widget\NestingLabelWidget'],
  126. 'multicheckbox' => ['Cake\View\Widget\MultiCheckboxWidget', 'nestingLabel'],
  127. 'radio' => ['Cake\View\Widget\RadioWidget', 'nestingLabel'],
  128. 'select' => ['Cake\View\Widget\SelectBoxWidget'],
  129. 'textarea' => ['Cake\View\Widget\TextareaWidget'],
  130. 'datetime' => ['Cake\View\Widget\DateTimeWidget', 'select'],
  131. '_default' => ['Cake\View\Widget\BasicWidget'],
  132. ];
  133. /**
  134. * List of fields created, used with secure forms.
  135. *
  136. * @var array
  137. */
  138. public $fields = [];
  139. /**
  140. * Constant used internally to skip the securing process,
  141. * and neither add the field to the hash or to the unlocked fields.
  142. *
  143. * @var string
  144. */
  145. const SECURE_SKIP = 'skip';
  146. /**
  147. * Defines the type of form being created. Set by FormHelper::create().
  148. *
  149. * @var string
  150. */
  151. public $requestType = null;
  152. /**
  153. * An array of field names that have been excluded from
  154. * the Token hash used by SecurityComponent's validatePost method
  155. *
  156. * @see FormHelper::_secure()
  157. * @see SecurityComponent::validatePost()
  158. * @var array
  159. */
  160. protected $_unlockedFields = [];
  161. /**
  162. * Registry for input widgets.
  163. *
  164. * @var \Cake\View\Widget\WidgetRegistry
  165. */
  166. protected $_registry;
  167. /**
  168. * Context for the current form.
  169. *
  170. * @var \Cake\View\Form\ContextInterface
  171. */
  172. protected $_context;
  173. /**
  174. * Context provider methods.
  175. *
  176. * @var array
  177. * @see addContextProvider
  178. */
  179. protected $_contextProviders = [];
  180. /**
  181. * The action attribute value of the last created form.
  182. * Used to make form/request specific hashes for SecurityComponent.
  183. *
  184. * @var string
  185. */
  186. protected $_lastAction = '';
  187. /**
  188. * Construct the widgets and binds the default context providers
  189. *
  190. * @param \Cake\View\View $View The View this helper is being attached to.
  191. * @param array $config Configuration settings for the helper.
  192. */
  193. public function __construct(View $View, array $config = [])
  194. {
  195. $registry = null;
  196. $widgets = $this->_defaultWidgets;
  197. if (isset($config['registry'])) {
  198. $registry = $config['registry'];
  199. unset($config['registry']);
  200. }
  201. if (isset($config['widgets'])) {
  202. if (is_string($config['widgets'])) {
  203. $config['widgets'] = (array)$config['widgets'];
  204. }
  205. $widgets = $config['widgets'] + $widgets;
  206. unset($config['widgets']);
  207. }
  208. parent::__construct($View, $config);
  209. $this->widgetRegistry($registry, $widgets);
  210. $this->_addDefaultContextProviders();
  211. }
  212. /**
  213. * Set the widget registry the helper will use.
  214. *
  215. * @param \Cake\View\Widget\WidgetRegistry $instance The registry instance to set.
  216. * @param array $widgets An array of widgets
  217. * @return \Cake\View\Widget\WidgetRegistry
  218. */
  219. public function widgetRegistry(WidgetRegistry $instance = null, $widgets = [])
  220. {
  221. if ($instance === null) {
  222. if ($this->_registry === null) {
  223. $this->_registry = new WidgetRegistry($this->templater(), $this->_View, $widgets);
  224. }
  225. return $this->_registry;
  226. }
  227. $this->_registry = $instance;
  228. return $this->_registry;
  229. }
  230. /**
  231. * Add the default suite of context providers provided by CakePHP.
  232. *
  233. * @return void
  234. */
  235. protected function _addDefaultContextProviders()
  236. {
  237. $this->addContextProvider('orm', function ($request, $data) {
  238. if (is_array($data['entity']) || $data['entity'] instanceof Traversable) {
  239. $pass = (new Collection($data['entity']))->first() !== null;
  240. if ($pass) {
  241. return new EntityContext($request, $data);
  242. }
  243. }
  244. if ($data['entity'] instanceof Entity) {
  245. return new EntityContext($request, $data);
  246. }
  247. if (is_array($data['entity']) && empty($data['entity']['schema'])) {
  248. return new EntityContext($request, $data);
  249. }
  250. });
  251. $this->addContextProvider('form', function ($request, $data) {
  252. if ($data['entity'] instanceof Form) {
  253. return new FormContext($request, $data);
  254. }
  255. });
  256. $this->addContextProvider('array', function ($request, $data) {
  257. if (is_array($data['entity']) && isset($data['entity']['schema'])) {
  258. return new ArrayContext($request, $data['entity']);
  259. }
  260. });
  261. }
  262. /**
  263. * Returns if a field is required to be filled based on validation properties from the validating object.
  264. *
  265. * @param \Cake\Validation\ValidationSet $validationRules Validation rules set.
  266. * @return bool true if field is required to be filled, false otherwise
  267. */
  268. protected function _isRequiredField($validationRules)
  269. {
  270. if (empty($validationRules) || count($validationRules) === 0) {
  271. return false;
  272. }
  273. $validationRules->isUpdate($this->requestType === 'put');
  274. foreach ($validationRules as $rule) {
  275. if ($rule->skip()) {
  276. continue;
  277. }
  278. return !$validationRules->isEmptyAllowed();
  279. }
  280. return false;
  281. }
  282. /**
  283. * Returns an HTML FORM element.
  284. *
  285. * ### Options:
  286. *
  287. * - `type` Form method defaults to autodetecting based on the form context. If
  288. * the form context's isCreate() method returns false, a PUT request will be done.
  289. * - `action` The controller action the form submits to, (optional). Use this option if you
  290. * don't need to change the controller from the current request's controller.
  291. * - `url` The URL the form submits to. Can be a string or a URL array. If you use 'url'
  292. * you should leave 'action' undefined.
  293. * - `encoding` Set the accept-charset encoding for the form. Defaults to `Configure::read('App.encoding')`
  294. * - `templates` The templates you want to use for this form. Any templates will be merged on top of
  295. * the already loaded templates. This option can either be a filename in /config that contains
  296. * the templates you want to load, or an array of templates to use.
  297. * - `context` Additional options for the context class. For example the EntityContext accepts a 'table'
  298. * option that allows you to set the specific Table class the form should be based on.
  299. * - `idPrefix` Prefix for generated ID attributes.
  300. *
  301. * @param mixed $model The context for which the form is being defined. Can
  302. * be an ORM entity, ORM resultset, or an array of meta data. You can use false or null
  303. * to make a model-less form.
  304. * @param array $options An array of html attributes and options.
  305. * @return string An formatted opening FORM tag.
  306. * @link http://book.cakephp.org/3.0/en/views/helpers/form.html#Cake\View\Helper\FormHelper::create
  307. */
  308. public function create($model = null, array $options = [])
  309. {
  310. $append = '';
  311. if (empty($options['context'])) {
  312. $options['context'] = [];
  313. }
  314. $options['context']['entity'] = $model;
  315. $context = $this->_getContext($options['context']);
  316. unset($options['context']);
  317. $isCreate = $context->isCreate();
  318. $options += [
  319. 'type' => $isCreate ? 'post' : 'put',
  320. 'action' => null,
  321. 'url' => null,
  322. 'encoding' => strtolower(Configure::read('App.encoding')),
  323. 'templates' => null,
  324. 'idPrefix' => null,
  325. ];
  326. $this->_idPrefix = $options['idPrefix'];
  327. $templater = $this->templater();
  328. if (!empty($options['templates'])) {
  329. $templater->push();
  330. $method = is_string($options['templates']) ? 'load' : 'add';
  331. $templater->{$method}($options['templates']);
  332. }
  333. unset($options['templates']);
  334. $url = $this->_formUrl($context, $options);
  335. $action = $this->Url->build($url);
  336. unset($options['url'], $options['action'], $options['idPrefix']);
  337. $this->_lastAction($url);
  338. $htmlAttributes = [];
  339. switch (strtolower($options['type'])) {
  340. case 'get':
  341. $htmlAttributes['method'] = 'get';
  342. break;
  343. // Set enctype for form
  344. case 'file':
  345. $htmlAttributes['enctype'] = 'multipart/form-data';
  346. $options['type'] = ($isCreate) ? 'post' : 'put';
  347. // Move on
  348. case 'post':
  349. // Move on
  350. case 'put':
  351. // Move on
  352. case 'delete':
  353. // Set patch method
  354. case 'patch':
  355. $append .= $this->hidden('_method', [
  356. 'name' => '_method',
  357. 'value' => strtoupper($options['type']),
  358. 'secure' => static::SECURE_SKIP
  359. ]);
  360. // Default to post method
  361. default:
  362. $htmlAttributes['method'] = 'post';
  363. }
  364. $this->requestType = strtolower($options['type']);
  365. if (!empty($options['encoding'])) {
  366. $htmlAttributes['accept-charset'] = $options['encoding'];
  367. }
  368. unset($options['type'], $options['encoding']);
  369. $htmlAttributes += $options;
  370. $this->fields = [];
  371. if ($this->requestType !== 'get') {
  372. $append .= $this->_csrfField();
  373. }
  374. if (!empty($append)) {
  375. $append = $templater->format('hiddenBlock', ['content' => $append]);
  376. }
  377. $actionAttr = $templater->formatAttributes(['action' => $action, 'escape' => false]);
  378. return $templater->format('formStart', [
  379. 'attrs' => $templater->formatAttributes($htmlAttributes) . $actionAttr
  380. ]) . $append;
  381. }
  382. /**
  383. * Create the URL for a form based on the options.
  384. *
  385. * @param \Cake\View\Form\ContextInterface $context The context object to use.
  386. * @param array $options An array of options from create()
  387. * @return string The action attribute for the form.
  388. */
  389. protected function _formUrl($context, $options)
  390. {
  391. if ($options['action'] === null && $options['url'] === null) {
  392. return $this->request->here(false);
  393. }
  394. if (is_string($options['url']) ||
  395. (is_array($options['url']) && isset($options['url']['_name']))
  396. ) {
  397. return $options['url'];
  398. }
  399. if (isset($options['action']) && empty($options['url']['action'])) {
  400. $options['url']['action'] = $options['action'];
  401. }
  402. $actionDefaults = [
  403. 'plugin' => $this->plugin,
  404. 'controller' => $this->request->params['controller'],
  405. 'action' => $this->request->params['action'],
  406. ];
  407. $action = (array)$options['url'] + $actionDefaults;
  408. $pk = $context->primaryKey();
  409. if (count($pk)) {
  410. $id = $context->val($pk[0]);
  411. }
  412. if (empty($action[0]) && isset($id)) {
  413. $action[0] = $id;
  414. }
  415. return $action;
  416. }
  417. /**
  418. * Correctly store the last created form action URL.
  419. *
  420. * @param string|array $url The URL of the last form.
  421. * @return void
  422. */
  423. protected function _lastAction($url)
  424. {
  425. $action = Router::url($url, true);
  426. $query = parse_url($action, PHP_URL_QUERY);
  427. $query = $query ? '?' . $query : '';
  428. $this->_lastAction = parse_url($action, PHP_URL_PATH) . $query;
  429. }
  430. /**
  431. * Return a CSRF input if the request data is present.
  432. * Used to secure forms in conjunction with CsrfComponent &
  433. * SecurityComponent
  434. *
  435. * @return string
  436. */
  437. protected function _csrfField()
  438. {
  439. if (!empty($this->request['_Token']['unlockedFields'])) {
  440. foreach ((array)$this->request['_Token']['unlockedFields'] as $unlocked) {
  441. $this->_unlockedFields[] = $unlocked;
  442. }
  443. }
  444. if (empty($this->request->params['_csrfToken'])) {
  445. return '';
  446. }
  447. return $this->hidden('_csrfToken', [
  448. 'value' => $this->request->params['_csrfToken'],
  449. 'secure' => static::SECURE_SKIP
  450. ]);
  451. }
  452. /**
  453. * Closes an HTML form, cleans up values set by FormHelper::create(), and writes hidden
  454. * input fields where appropriate.
  455. *
  456. * @param array $secureAttributes Secure attibutes which will be passed as HTML attributes
  457. * into the hidden input elements generated for the Security Component.
  458. * @return string A closing FORM tag.
  459. * @link http://book.cakephp.org/3.0/en/views/helpers/form.html#closing-the-form
  460. */
  461. public function end(array $secureAttributes = [])
  462. {
  463. $out = '';
  464. if ($this->requestType !== 'get' &&
  465. !empty($this->request['_Token'])
  466. ) {
  467. $out .= $this->secure($this->fields, $secureAttributes);
  468. $this->fields = [];
  469. }
  470. $templater = $this->templater();
  471. $out .= $templater->format('formEnd', []);
  472. $templater->pop();
  473. $this->requestType = null;
  474. $this->_context = null;
  475. $this->_idPrefix = null;
  476. return $out;
  477. }
  478. /**
  479. * Generates a hidden field with a security hash based on the fields used in
  480. * the form.
  481. *
  482. * If $secureAttributes is set, these HTML attributes will be merged into
  483. * the hidden input tags generated for the Security Component. This is
  484. * especially useful to set HTML5 attributes like 'form'.
  485. *
  486. * @param array $fields If set specifies the list of fields to use when
  487. * generating the hash, else $this->fields is being used.
  488. * @param array $secureAttributes will be passed as HTML attributes into the hidden
  489. * input elements generated for the Security Component.
  490. * @return string A hidden input field with a security hash
  491. */
  492. public function secure(array $fields = [], array $secureAttributes = [])
  493. {
  494. if (!isset($this->request['_Token']) || empty($this->request['_Token'])) {
  495. return;
  496. }
  497. $locked = [];
  498. $unlockedFields = $this->_unlockedFields;
  499. foreach ($fields as $key => $value) {
  500. if (!is_int($key)) {
  501. $locked[$key] = $value;
  502. unset($fields[$key]);
  503. }
  504. }
  505. sort($unlockedFields, SORT_STRING);
  506. sort($fields, SORT_STRING);
  507. ksort($locked, SORT_STRING);
  508. $fields += $locked;
  509. $locked = implode(array_keys($locked), '|');
  510. $unlocked = implode($unlockedFields, '|');
  511. $hashParts = [
  512. $this->_lastAction,
  513. serialize($fields),
  514. $unlocked,
  515. Security::salt()
  516. ];
  517. $fields = Security::hash(implode('', $hashParts), 'sha1');
  518. $tokenFields = array_merge($secureAttributes, [
  519. 'value' => urlencode($fields . ':' . $locked),
  520. ]);
  521. $out = $this->hidden('_Token.fields', $tokenFields);
  522. $tokenUnlocked = array_merge($secureAttributes, [
  523. 'value' => urlencode($unlocked),
  524. ]);
  525. $out .= $this->hidden('_Token.unlocked', $tokenUnlocked);
  526. return $this->formatTemplate('hiddenBlock', ['content' => $out]);
  527. }
  528. /**
  529. * Add to or get the list of fields that are currently unlocked.
  530. * Unlocked fields are not included in the field hash used by SecurityComponent
  531. * unlocking a field once its been added to the list of secured fields will remove
  532. * it from the list of fields.
  533. *
  534. * @param string|null $name The dot separated name for the field.
  535. * @return mixed Either null, or the list of fields.
  536. * @link http://book.cakephp.org/3.0/en/views/helpers/form.html#working-with-securitycomponent
  537. */
  538. public function unlockField($name = null)
  539. {
  540. if ($name === null) {
  541. return $this->_unlockedFields;
  542. }
  543. if (!in_array($name, $this->_unlockedFields)) {
  544. $this->_unlockedFields[] = $name;
  545. }
  546. $index = array_search($name, $this->fields);
  547. if ($index !== false) {
  548. unset($this->fields[$index]);
  549. }
  550. unset($this->fields[$name]);
  551. }
  552. /**
  553. * Determine which fields of a form should be used for hash.
  554. * Populates $this->fields
  555. *
  556. * @param bool $lock Whether this field should be part of the validation
  557. * or excluded as part of the unlockedFields.
  558. * @param string|array $field Reference to field to be secured. Can be dot
  559. * separated string to indicate nesting or array of fieldname parts.
  560. * @param mixed $value Field value, if value should not be tampered with.
  561. * @return mixed|null Not used yet
  562. */
  563. protected function _secure($lock, $field, $value = null)
  564. {
  565. if (is_string($field)) {
  566. $field = Hash::filter(explode('.', $field));
  567. }
  568. foreach ($this->_unlockedFields as $unlockField) {
  569. $unlockParts = explode('.', $unlockField);
  570. if (array_values(array_intersect($field, $unlockParts)) === $unlockParts) {
  571. return;
  572. }
  573. }
  574. $field = implode('.', $field);
  575. $field = preg_replace('/(\.\d+)+$/', '', $field);
  576. if ($lock) {
  577. if (!in_array($field, $this->fields)) {
  578. if ($value !== null) {
  579. return $this->fields[$field] = $value;
  580. }
  581. $this->fields[] = $field;
  582. }
  583. } else {
  584. $this->unlockField($field);
  585. }
  586. }
  587. /**
  588. * Returns true if there is an error for the given field, otherwise false
  589. *
  590. * @param string $field This should be "modelname.fieldname"
  591. * @return bool If there are errors this method returns true, else false.
  592. * @link http://book.cakephp.org/3.0/en/views/helpers/form.html#displaying-and-checking-errors
  593. */
  594. public function isFieldError($field)
  595. {
  596. return $this->_getContext()->hasError($field);
  597. }
  598. /**
  599. * Returns a formatted error message for given form field, '' if no errors.
  600. *
  601. * Uses the `error`, `errorList` and `errorItem` templates. The `errorList` and
  602. * `errorItem` templates are used to format multiple error messages per field.
  603. *
  604. * ### Options:
  605. *
  606. * - `escape` boolean - Whether or not to html escape the contents of the error.
  607. *
  608. * @param string $field A field name, like "modelname.fieldname"
  609. * @param string|array $text Error message as string or array of messages. If an array,
  610. * it should be a hash of key names => messages.
  611. * @param array $options See above.
  612. * @return string Formatted errors or ''.
  613. * @link http://book.cakephp.org/3.0/en/views/helpers/form.html#displaying-and-checking-errors
  614. */
  615. public function error($field, $text = null, array $options = [])
  616. {
  617. if (substr($field, -5) === '._ids') {
  618. $field = substr($field, 0, -5);
  619. }
  620. $options += ['escape' => true];
  621. $context = $this->_getContext();
  622. if (!$context->hasError($field)) {
  623. return '';
  624. }
  625. $error = (array)$context->error($field);
  626. if (is_array($text)) {
  627. $tmp = [];
  628. foreach ($error as $e) {
  629. if (isset($text[$e])) {
  630. $tmp[] = $text[$e];
  631. } else {
  632. $tmp[] = $e;
  633. }
  634. }
  635. $text = $tmp;
  636. }
  637. if ($text !== null) {
  638. $error = $text;
  639. }
  640. if ($options['escape']) {
  641. $error = h($error);
  642. unset($options['escape']);
  643. }
  644. if (is_array($error)) {
  645. if (count($error) > 1) {
  646. $errorText = [];
  647. foreach ($error as $err) {
  648. $errorText[] = $this->formatTemplate('errorItem', ['text' => $err]);
  649. }
  650. $error = $this->formatTemplate('errorList', [
  651. 'content' => implode('', $errorText)
  652. ]);
  653. } else {
  654. $error = array_pop($error);
  655. }
  656. }
  657. return $this->formatTemplate('error', ['content' => $error]);
  658. }
  659. /**
  660. * Returns a formatted LABEL element for HTML forms.
  661. *
  662. * Will automatically generate a `for` attribute if one is not provided.
  663. *
  664. * ### Options
  665. *
  666. * - `for` - Set the for attribute, if its not defined the for attribute
  667. * will be generated from the $fieldName parameter using
  668. * FormHelper::_domId().
  669. *
  670. * Examples:
  671. *
  672. * The text and for attribute are generated off of the fieldname
  673. *
  674. * ```
  675. * echo $this->Form->label('published');
  676. * <label for="PostPublished">Published</label>
  677. * ```
  678. *
  679. * Custom text:
  680. *
  681. * ```
  682. * echo $this->Form->label('published', 'Publish');
  683. * <label for="published">Publish</label>
  684. * ```
  685. *
  686. * Custom attributes:
  687. *
  688. * ```
  689. * echo $this->Form->label('published', 'Publish', [
  690. * 'for' => 'post-publish'
  691. * ]);
  692. * <label for="post-publish">Publish</label>
  693. * ```
  694. *
  695. * Nesting an input tag:
  696. *
  697. * ```
  698. * echo $this->Form->label('published', 'Publish', [
  699. * 'for' => 'published',
  700. * 'input' => $this->text('published'),
  701. * ]);
  702. * <label for="post-publish">Publish <input type="text" name="published"></label>
  703. * ```
  704. *
  705. * If you want to nest inputs in the labels, you will need to modify the default templates.
  706. *
  707. * @param string $fieldName This should be "modelname.fieldname"
  708. * @param string $text Text that will appear in the label field. If
  709. * $text is left undefined the text will be inflected from the
  710. * fieldName.
  711. * @param array $options An array of HTML attributes.
  712. * @return string The formatted LABEL element
  713. * @link http://book.cakephp.org/3.0/en/views/helpers/form.html#creating-labels
  714. */
  715. public function label($fieldName, $text = null, array $options = [])
  716. {
  717. if ($text === null) {
  718. $text = $fieldName;
  719. if (substr($text, -5) === '._ids') {
  720. $text = substr($text, 0, -5);
  721. }
  722. if (strpos($text, '.') !== false) {
  723. $fieldElements = explode('.', $text);
  724. $text = array_pop($fieldElements);
  725. }
  726. if (substr($text, -3) === '_id') {
  727. $text = substr($text, 0, -3);
  728. }
  729. $text = __(Inflector::humanize(Inflector::underscore($text)));
  730. }
  731. if (isset($options['for'])) {
  732. $labelFor = $options['for'];
  733. unset($options['for']);
  734. } else {
  735. $labelFor = $this->_domId($fieldName);
  736. }
  737. $attrs = $options + [
  738. 'for' => $labelFor,
  739. 'text' => $text,
  740. ];
  741. if (isset($options['input'])) {
  742. if (is_array($options['input'])) {
  743. $attrs = $options['input'] + $attrs;
  744. }
  745. return $this->widget('nestingLabel', $attrs);
  746. }
  747. return $this->widget('label', $attrs);
  748. }
  749. /**
  750. * Generate a set of inputs for `$fields`. If $fields is empty the fields of current model
  751. * will be used.
  752. *
  753. * You can customize individual inputs through `$fields`.
  754. * ```
  755. * $this->Form->allInputs([
  756. * 'name' => ['label' => 'custom label']
  757. * ]);
  758. * ```
  759. *
  760. * You can exclude fields by specifying them as false:
  761. *
  762. * ```
  763. * $this->Form->allInputs(['title' => false]);
  764. * ```
  765. *
  766. * In the above example, no field would be generated for the title field.
  767. *
  768. * @param array $fields An array of customizations for the fields that will be
  769. * generated. This array allows you to set custom types, labels, or other options.
  770. * @param array $options Options array. Valid keys are:
  771. * - `fieldset` Set to false to disable the fieldset.
  772. * - `legend` Set to false to disable the legend for the generated input set. Or supply a string
  773. * to customize the legend text.
  774. * @return string Completed form inputs.
  775. * @link http://book.cakephp.org/3.0/en/views/helpers/form.html#generating-entire-forms
  776. */
  777. public function allInputs(array $fields = [], array $options = [])
  778. {
  779. $context = $this->_getContext();
  780. $modelFields = $context->fieldNames();
  781. $fields = array_merge(
  782. Hash::normalize($modelFields),
  783. Hash::normalize($fields)
  784. );
  785. return $this->inputs($fields, $options);
  786. }
  787. /**
  788. * Generate a set of inputs for `$fields` wrapped in a fieldset element.
  789. *
  790. * You can customize individual inputs through `$fields`.
  791. * ```
  792. * $this->Form->inputs([
  793. * 'name' => ['label' => 'custom label'],
  794. * 'email'
  795. * ]);
  796. * ```
  797. *
  798. * @param array $fields An array of the fields to generate. This array allows you to set custom
  799. * types, labels, or other options.
  800. * @param array $options Options array. Valid keys are:
  801. * - `fieldset` Set to false to disable the fieldset.
  802. * - `legend` Set to false to disable the legend for the generated input set. Or supply a string
  803. * to customize the legend text.
  804. * @return string Completed form inputs.
  805. * @link http://book.cakephp.org/3.0/en/views/helpers/form.html#generating-entire-forms
  806. */
  807. public function inputs(array $fields, array $options = [])
  808. {
  809. $fields = Hash::normalize($fields);
  810. $out = '';
  811. foreach ($fields as $name => $opts) {
  812. if ($opts === false) {
  813. continue;
  814. }
  815. $out .= $this->input($name, (array)$opts);
  816. }
  817. return $this->fieldset($out, $options);
  818. }
  819. /**
  820. * Wrap a set of inputs in a fieldset
  821. *
  822. * @param string $fields the form inputs to wrap in a fieldset
  823. * @param array $options Options array. Valid keys are:
  824. * - `fieldset` Set to false to disable the fieldset.
  825. * - `legend` Set to false to disable the legend for the generated input set. Or supply a string
  826. * to customize the legend text.
  827. * @return string Completed form inputs.
  828. */
  829. public function fieldset($fields = '', array $options = [])
  830. {
  831. $fieldset = $legend = true;
  832. $context = $this->_getContext();
  833. $out = $fields;
  834. if (isset($options['legend'])) {
  835. $legend = $options['legend'];
  836. }
  837. if (isset($options['fieldset'])) {
  838. $fieldset = $options['fieldset'];
  839. }
  840. if ($legend === true) {
  841. $actionName = __d('cake', 'New %s');
  842. $isCreate = $context->isCreate();
  843. if (!$isCreate) {
  844. $actionName = __d('cake', 'Edit %s');
  845. }
  846. $modelName = Inflector::humanize(Inflector::singularize($this->request->params['controller']));
  847. $legend = sprintf($actionName, $modelName);
  848. }
  849. if ($fieldset) {
  850. if ($legend) {
  851. $out = $this->formatTemplate('legend', ['text' => $legend]) . $out;
  852. }
  853. $out = $this->formatTemplate('fieldset', ['content' => $out]);
  854. }
  855. return $out;
  856. }
  857. /**
  858. * Generates a form input element complete with label and wrapper div
  859. *
  860. * ### Options
  861. *
  862. * See each field type method for more information. Any options that are part of
  863. * $attributes or $options for the different **type** methods can be included in `$options` for input().
  864. * Additionally, any unknown keys that are not in the list below, or part of the selected type's options
  865. * will be treated as a regular HTML attribute for the generated input.
  866. *
  867. * - `type` - Force the type of widget you want. e.g. `type => 'select'`
  868. * - `label` - Either a string label, or an array of options for the label. See FormHelper::label().
  869. * - `options` - For widgets that take options e.g. radio, select.
  870. * - `error` - Control the error message that is produced. Set to `false` to disable any kind of error reporting (field
  871. * error and error messages).
  872. * - `empty` - String or boolean to enable empty select box options.
  873. * - `nestedInput` - Used with checkbox and radio inputs. Set to false to render inputs outside of label
  874. * elements. Can be set to true on any input to force the input inside the label. If you
  875. * enable this option for radio buttons you will also need to modify the default `radioWrapper` template.
  876. *
  877. * @param string $fieldName This should be "modelname.fieldname"
  878. * @param array $options Each type of input takes different options.
  879. * @return string Completed form widget.
  880. * @link http://book.cakephp.org/3.0/en/views/helpers/form.html#creating-form-inputs
  881. */
  882. public function input($fieldName, array $options = [])
  883. {
  884. $options += [
  885. 'type' => null,
  886. 'label' => null,
  887. 'error' => null,
  888. 'required' => null,
  889. 'options' => null,
  890. 'templates' => [],
  891. ];
  892. $options = $this->_parseOptions($fieldName, $options);
  893. $options += ['id' => $this->_domId($fieldName)];
  894. $templater = $this->templater();
  895. $newTemplates = $options['templates'];
  896. if ($newTemplates) {
  897. $templater->push();
  898. $templateMethod = is_string($options['templates']) ? 'load' : 'add';
  899. $templater->{$templateMethod}($options['templates']);
  900. }
  901. unset($options['templates']);
  902. $error = null;
  903. $errorSuffix = '';
  904. if ($options['type'] !== 'hidden' && $options['error'] !== false) {
  905. $error = $this->error($fieldName, $options['error']);
  906. $errorSuffix = empty($error) ? '' : 'Error';
  907. unset($options['error']);
  908. }
  909. $label = $options['label'];
  910. unset($options['label']);
  911. $nestedInput = false;
  912. if ($options['type'] === 'checkbox') {
  913. $nestedInput = true;
  914. }
  915. $nestedInput = isset($options['nestedInput']) ? $options['nestedInput'] : $nestedInput;
  916. if ($nestedInput === true && $options['type'] === 'checkbox' && !array_key_exists('hiddenField', $options) && $label !== false) {
  917. $options['hiddenField'] = '_split';
  918. }
  919. $input = $this->_getInput($fieldName, $options);
  920. if ($options['type'] === 'hidden') {
  921. if ($newTemplates) {
  922. $templater->pop();
  923. }
  924. return $input;
  925. }
  926. $label = $this->_getLabel($fieldName, compact('input', 'label', 'error', 'nestedInput') + $options);
  927. $result = $this->_groupTemplate(compact('input', 'label', 'error', 'options'));
  928. $result = $this->_inputContainerTemplate([
  929. 'content' => $result,
  930. 'error' => $error,
  931. 'errorSuffix' => $errorSuffix,
  932. 'options' => $options
  933. ]);
  934. if ($newTemplates) {
  935. $templater->pop();
  936. }
  937. return $result;
  938. }
  939. /**
  940. * Generates an group template element
  941. *
  942. * @param array $options The options for group template
  943. * @return string The generated group template
  944. */
  945. protected function _groupTemplate($options)
  946. {
  947. $groupTemplate = $options['options']['type'] === 'checkbox' ? 'checkboxFormGroup' : 'formGroup';
  948. return $this->templater()->format($groupTemplate, [
  949. 'input' => $options['input'],
  950. 'label' => $options['label'],
  951. 'error' => $options['error']
  952. ]);
  953. }
  954. /**
  955. * Generates an input container template
  956. *
  957. * @param array $options The options for input container template
  958. * @return string The generated input container template
  959. */
  960. protected function _inputContainerTemplate($options)
  961. {
  962. $inputContainerTemplate = $options['options']['type'] . 'Container' . $options['errorSuffix'];
  963. if (!$this->templater()->get($inputContainerTemplate)) {
  964. $inputContainerTemplate = 'inputContainer' . $options['errorSuffix'];
  965. }
  966. return $this->templater()->format($inputContainerTemplate, [
  967. 'content' => $options['content'],
  968. 'error' => $options['error'],
  969. 'required' => $options['options']['required'] ? ' required' : '',
  970. 'type' => $options['options']['type']
  971. ]);
  972. }
  973. /**
  974. * Generates an input element
  975. *
  976. * @param string $fieldName the field name
  977. * @param array $options The options for the input element
  978. * @return string The generated input element
  979. */
  980. protected function _getInput($fieldName, $options)
  981. {
  982. switch ($options['type']) {
  983. case 'select':
  984. $opts = $options['options'];
  985. unset($options['options']);
  986. return $this->select($fieldName, $opts, $options);
  987. case 'radio':
  988. $opts = $options['options'];
  989. unset($options['options']);
  990. return $this->radio($fieldName, $opts, $options);
  991. case 'multicheckbox':
  992. $opts = $options['options'];
  993. unset($options['options']);
  994. return $this->multicheckbox($fieldName, $opts, $options);
  995. case 'url':
  996. $options = $this->_initInputField($fieldName, $options);
  997. return $this->widget($options['type'], $options);
  998. default:
  999. return $this->{$options['type']}($fieldName, $options);
  1000. }
  1001. }
  1002. /**
  1003. * Generates input options array
  1004. *
  1005. * @param string $fieldName The name of the field to parse options for.
  1006. * @param array $options Options list.
  1007. * @return array Options
  1008. */
  1009. protected function _parseOptions($fieldName, $options)
  1010. {
  1011. $needsMagicType = false;
  1012. if (empty($options['type'])) {
  1013. $needsMagicType = true;
  1014. $options['type'] = $this->_inputType($fieldName, $options);
  1015. }
  1016. $options = $this->_magicOptions($fieldName, $options, $needsMagicType);
  1017. return $options;
  1018. }
  1019. /**
  1020. * Returns the input type that was guessed for the provided fieldName,
  1021. * based on the internal type it is associated too, its name and the
  1022. * variables that can be found in the view template
  1023. *
  1024. * @param string $fieldName the name of the field to guess a type for
  1025. * @param array $options the options passed to the input method
  1026. * @return string
  1027. */
  1028. protected function _inputType($fieldName, $options)
  1029. {
  1030. $context = $this->_getContext();
  1031. if ($context->isPrimaryKey($fieldName)) {
  1032. return 'hidden';
  1033. }
  1034. if (substr($fieldName, -3) === '_id') {
  1035. return 'select';
  1036. }
  1037. $internalType = $context->type($fieldName);
  1038. $map = $this->_config['typeMap'];
  1039. $type = isset($map[$internalType]) ? $map[$internalType] : 'text';
  1040. $fieldName = array_slice(explode('.', $fieldName), -1)[0];
  1041. switch (true) {
  1042. case isset($options['checked']):
  1043. return 'checkbox';
  1044. case isset($options['options']):
  1045. return 'select';
  1046. case in_array($fieldName, ['passwd', 'password']):
  1047. return 'password';
  1048. case in_array($fieldName, ['tel', 'telephone', 'phone']):
  1049. return 'tel';
  1050. case $fieldName === 'email':
  1051. return 'email';
  1052. case isset($options['rows']) || isset($options['cols']):
  1053. return 'textarea';
  1054. }
  1055. return $type;
  1056. }
  1057. /**
  1058. * Selects the variable containing the options for a select field if present,
  1059. * and sets the value to the 'options' key in the options array.
  1060. *
  1061. * @param string $fieldName The name of the field to find options for.
  1062. * @param array $options Options list.
  1063. * @return array
  1064. */
  1065. protected function _optionsOptions($fieldName, $options)
  1066. {
  1067. if (isset($options['options'])) {
  1068. return $options;
  1069. }
  1070. $pluralize = true;
  1071. if (substr($fieldName, -5) === '._ids') {
  1072. $fieldName = substr($fieldName, 0, -5);
  1073. $pluralize = false;
  1074. } elseif (substr($fieldName, -3) === '_id') {
  1075. $fieldName = substr($fieldName, 0, -3);
  1076. }
  1077. $fieldName = array_slice(explode('.', $fieldName), -1)[0];
  1078. $varName = Inflector::variable(
  1079. $pluralize ? Inflector::pluralize($fieldName) : $fieldName
  1080. );
  1081. $varOptions = $this->_View->get($varName);
  1082. if (!is_array($varOptions) && !($varOptions instanceof Traversable)) {
  1083. return $options;
  1084. }
  1085. if ($options['type'] !== 'radio') {
  1086. $options['type'] = 'select';
  1087. }
  1088. $options['options'] = $varOptions;
  1089. return $options;
  1090. }
  1091. /**
  1092. * Magically set option type and corresponding options
  1093. *
  1094. * @param string $fieldName The name of the field to generate options for.
  1095. * @param array $options Options list.
  1096. * @param bool $allowOverride Whether or not it is allowed for this method to
  1097. * overwrite the 'type' key in options.
  1098. * @return array
  1099. */
  1100. protected function _magicOptions($fieldName, $options, $allowOverride)
  1101. {
  1102. $context = $this->_getContext();
  1103. if (!isset($options['required']) && $options['type'] !== 'hidden') {
  1104. $options['required'] = $context->isRequired($fieldName);
  1105. }
  1106. $type = $context->type($fieldName);
  1107. $fieldDef = $context->attributes($fieldName);
  1108. if ($options['type'] === 'number' && !isset($options['step'])) {
  1109. if ($type === 'decimal' && isset($fieldDef['precision'])) {
  1110. $decimalPlaces = $fieldDef['precision'];
  1111. $options['step'] = sprintf('%.' . $decimalPlaces . 'F', pow(10, -1 * $decimalPlaces));
  1112. } elseif ($type === 'float') {
  1113. $options['step'] = 'any';
  1114. }
  1115. }
  1116. $typesWithOptions = ['text', 'number', 'radio', 'select'];
  1117. $magicOptions = (in_array($options['type'], ['radio', 'select']) || $allowOverride);
  1118. if ($magicOptions && in_array($options['type'], $typesWithOptions)) {
  1119. $options = $this->_optionsOptions($fieldName, $options);
  1120. }
  1121. if ($allowOverride && substr($fieldName, -5) === '._ids') {
  1122. $options['type'] = 'select';
  1123. if (empty($options['multiple'])) {
  1124. $options['multiple'] = true;
  1125. }
  1126. }
  1127. if ($options['type'] === 'select' && array_key_exists('step', $options)) {
  1128. unset($options['step']);
  1129. }
  1130. $autoLength = !array_key_exists('maxlength', $options)
  1131. && !empty($fieldDef['length'])
  1132. && $options['type'] !== 'select';
  1133. $allowedTypes = ['text', 'textarea', 'email', 'tel', 'url', 'search'];
  1134. if ($autoLength && in_array($options['type'], $allowedTypes)) {
  1135. $options['maxlength'] = min($fieldDef['length'], 100000);
  1136. }
  1137. if (in_array($options['type'], ['datetime', 'date', 'time', 'select'])) {
  1138. $options += ['empty' => false];
  1139. }
  1140. return $options;
  1141. }
  1142. /**
  1143. * Generate label for input
  1144. *
  1145. * @param string $fieldName The name of the field to generate label for.
  1146. * @param array $options Options list.
  1147. * @return bool|string false or Generated label element
  1148. */
  1149. protected function _getLabel($fieldName, $options)
  1150. {
  1151. if ($options['type'] === 'hidden') {
  1152. return false;
  1153. }
  1154. $label = null;
  1155. if (isset($options['label'])) {
  1156. $label = $options['label'];
  1157. }
  1158. if ($label === false && $options['type'] === 'checkbox') {
  1159. return $options['input'];
  1160. }
  1161. if ($label === false) {
  1162. return false;
  1163. }
  1164. return $this->_inputLabel($fieldName, $label, $options);
  1165. }
  1166. /**
  1167. * Extracts a single option from an options array.
  1168. *
  1169. * @param string $name The name of the option to pull out.
  1170. * @param array $options The array of options you want to extract.
  1171. * @param mixed $default The default option value
  1172. * @return mixed the contents of the option or default
  1173. */
  1174. protected function _extractOption($name, $options, $default = null)
  1175. {
  1176. if (array_key_exists($name, $options)) {
  1177. return $options[$name];
  1178. }
  1179. return $default;
  1180. }
  1181. /**
  1182. * Generate a label for an input() call.
  1183. *
  1184. * $options can contain a hash of id overrides. These overrides will be
  1185. * used instead of the generated values if present.
  1186. *
  1187. * @param string $fieldName The name of the field to generate label for.
  1188. * @param string $label Label text.
  1189. * @param array $options Options for the label element.
  1190. * @return string Generated label element
  1191. */
  1192. protected function _inputLabel($fieldName, $label, $options)
  1193. {
  1194. $labelAttributes = [];
  1195. if (is_array($label)) {
  1196. $labelText = null;
  1197. if (isset($label['text'])) {
  1198. $labelText = $label['text'];
  1199. unset($label['text']);
  1200. }
  1201. $labelAttributes = array_merge($labelAttributes, $label);
  1202. } else {
  1203. $labelText = $label;
  1204. }
  1205. $options += ['id' => null, 'input' => null, 'nestedInput' => false];
  1206. $labelAttributes['for'] = $options['id'];
  1207. $groupTypes = ['radio', 'multicheckbox', 'date', 'time', 'datetime'];
  1208. if (in_array($options['type'], $groupTypes, true)) {
  1209. $labelAttributes['for'] = false;
  1210. }
  1211. if ($options['nestedInput']) {
  1212. $labelAttributes['input'] = $options['input'];
  1213. }
  1214. return $this->label($fieldName, $labelText, $labelAttributes);
  1215. }
  1216. /**
  1217. * Creates a checkbox input widget.
  1218. *
  1219. * ### Options:
  1220. *
  1221. * - `value` - the value of the checkbox
  1222. * - `checked` - boolean indicate that this checkbox is checked.
  1223. * - `hiddenField` - boolean to indicate if you want the results of checkbox() to include
  1224. * a hidden input with a value of ''.
  1225. * - `disabled` - create a disabled input.
  1226. * - `default` - Set the default value for the checkbox. This allows you to start checkboxes
  1227. * as checked, without having to check the POST data. A matching POST data value, will overwrite
  1228. * the default value.
  1229. *
  1230. * @param string $fieldName Name of a field, like this "modelname.fieldname"
  1231. * @param array $options Array of HTML attributes.
  1232. * @return string|array An HTML text input element.
  1233. * @link http://book.cakephp.org/3.0/en/views/helpers/form.html#creating-checkboxes
  1234. */
  1235. public function checkbox($fieldName, array $options = [])
  1236. {
  1237. $options += ['hiddenField' => true, 'value' => 1];
  1238. // Work around value=>val translations.
  1239. $value = $options['value'];
  1240. unset($options['value']);
  1241. $options = $this->_initInputField($fieldName, $options);
  1242. $options['value'] = $value;
  1243. $output = '';
  1244. if ($options['hiddenField']) {
  1245. $hiddenOptions = [
  1246. 'name' => $options['name'],
  1247. 'value' => ($options['hiddenField'] !== true && $options['hiddenField'] !== '_split' ? $options['hiddenField'] : '0'),
  1248. 'form' => isset($options['form']) ? $options['form'] : null,
  1249. 'secure' => false
  1250. ];
  1251. if (isset($options['disabled']) && $options['disabled']) {
  1252. $hiddenOptions['disabled'] = 'disabled';
  1253. }
  1254. $output = $this->hidden($fieldName, $hiddenOptions);
  1255. }
  1256. if ($options['hiddenField'] === '_split') {
  1257. unset($options['hiddenField'], $options['type']);
  1258. return ['hidden' => $output, 'input' => $this->widget('checkbox', $options)];
  1259. }
  1260. unset($options['hiddenField'], $options['type']);
  1261. return $output . $this->widget('checkbox', $options);
  1262. }
  1263. /**
  1264. * Creates a set of radio widgets.
  1265. *
  1266. * ### Attributes:
  1267. *
  1268. * - `value` - Indicates the value when this radio button is checked.
  1269. * - `label` - boolean to indicate whether or not labels for widgets should be displayed.
  1270. * - `hiddenField` - boolean to indicate if you want the results of radio() to include
  1271. * a hidden input with a value of ''. This is useful for…

Large files files are truncated, but you can click here to view the full file