PageRenderTime 52ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/QuickApps/View/Helper/QaFormHelper.php

http://github.com/QuickAppsCMS/QuickApps-CMS
PHP | 774 lines | 171 code | 83 blank | 520 comment | 1 complexity | 45422477b6c138f34ca72510ff07dec2 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception, GPL-3.0
  1. <?php
  2. /**
  3. * Form Helper
  4. *
  5. * PHP version 5
  6. *
  7. * @package QuickApps.View.Helper
  8. * @version 1.0
  9. * @author Christopher Castro <chris@quickapps.es>
  10. * @link http://www.quickappscms.org
  11. */
  12. class QaFormHelper extends AppHelper {
  13. /**
  14. * Other helpers used by QaFormHelper
  15. *
  16. * @var array
  17. * @access public
  18. */
  19. public $helpers = array('CoreForm' => array('className' => 'Form'));
  20. /**
  21. * Copies the validationErrors variable from the View object into this instance
  22. *
  23. * @param View $View The View this helper is being attached to.
  24. * @param array $settings Configuration settings for the helper.
  25. */
  26. public function __construct(View $View, $settings = array()) {
  27. parent::__construct($View, $settings);
  28. $this->CoreForm->validationErrors =& $View->validationErrors;
  29. }
  30. /**
  31. * Returns false if given form field described by the current entity has no errors.
  32. * Otherwise it returns the validation message
  33. *
  34. * @return boolean True on errors.
  35. */
  36. public function tagIsInvalid() {
  37. return $this->CoreForm->tagIsInvalid();
  38. }
  39. /**
  40. * Returns an HTML FORM element.
  41. *
  42. * ### Options:
  43. *
  44. * - `type` Form method defaults to POST
  45. * - `action` The controller action the form submits to, (optional).
  46. * - `url` The url the form submits to. Can be a string or a url array,
  47. * - `default` Allows for the creation of Ajax forms.
  48. * - `onsubmit` Used in conjunction with 'default' to create ajax forms.
  49. * - `inputDefaults` set the default $options for FormHelper::input(). Any options that would
  50. * be set when using FormHelper::input() can be set here. Options set with `inputDefaults`
  51. * can be overridden when calling input()
  52. * - `encoding` Set the accept-charset encoding for the form. Defaults to `Configure::read('App.encoding')`
  53. *
  54. * @access public
  55. * @param string $model The model object which the form is being defined for
  56. * @param array $options An array of html attributes and options.
  57. * @return string An formatted opening FORM tag.
  58. * @link http://book.cakephp.org/view/1384/Creating-Forms
  59. */
  60. public function create($model = null, $options = array()) {
  61. $data = compact('model', 'options');
  62. $this->hook('form_create_alter', $data);
  63. extract($data);
  64. return $this->CoreForm->create($model, $options);
  65. }
  66. /**
  67. * Closes an HTML form, cleans up values set by FormHelper::create(), and writes hidden
  68. * input fields where appropriate.
  69. *
  70. * If $options is set a form submit button will be created. Options can be either a string or an array.
  71. *
  72. * {{{
  73. * array usage:
  74. *
  75. * array('label' => 'save'); value="save"
  76. * array('label' => 'save', 'name' => 'Whatever'); value="save" name="Whatever"
  77. * array('name' => 'Whatever'); value="Submit" name="Whatever"
  78. * array('label' => 'save', 'name' => 'Whatever', 'div' => 'good') <div class="good"> value="save" name="Whatever"
  79. * array('label' => 'save', 'name' => 'Whatever', 'div' => array('class' => 'good')); <div class="good"> value="save" name="Whatever"
  80. * }}}
  81. *
  82. * @param mixed $options as a string will use $options as the value of button,
  83. * @return string a closing FORM tag optional submit button.
  84. * @access public
  85. * @link http://book.cakephp.org/view/1389/Closing-the-Form
  86. */
  87. public function end($options = null) {
  88. $this->hook('form_end_alter', $options);
  89. return $this->CoreForm->end($options);
  90. }
  91. /**
  92. * Generates a hidden field with a security hash based on the fields used in the form.
  93. *
  94. * @param array $fields The list of fields to use when generating the hash
  95. * @return string A hidden input field with a security hash
  96. */
  97. public function secure($fields = array()) {
  98. $this->hook('form_secure_alter', $fields);
  99. return $this->CoreForm->secure($fields);
  100. }
  101. /**
  102. * Add to or get the list of fields that are currently unlocked.
  103. * Unlocked fields are not included in the field hash used by SecurityComponent
  104. * unlocking a field once its been added to the list of secured fields will remove
  105. * it from the list of fields.
  106. *
  107. * @param string $name The dot separated name for the field.
  108. * @return mixed Either null, or the list of fields.
  109. */
  110. public function unlockField($name = null) {
  111. $this->hook('form_unlock_field_alter', $name);
  112. return $this->CoreForm->unlockField($name);
  113. }
  114. /**
  115. * Returns true if there is an error for the given field, otherwise false
  116. *
  117. * @param string $field This should be "Modelname.fieldname"
  118. * @return boolean If there are errors this method returns true, else false.
  119. * @access public
  120. * @link http://book.cakephp.org/view/1426/isFieldError
  121. */
  122. public function isFieldError($field) {
  123. $this->hook('form_is_field_error_alter', $field);
  124. return $this->CoreForm->isFieldError($field);
  125. }
  126. /**
  127. * Returns a formatted error message for given FORM field, NULL if no errors.
  128. *
  129. * ### Options:
  130. *
  131. * - `escape` bool Whether or not to html escape the contents of the error.
  132. * - `wrap` mixed Whether or not the error message should be wrapped in a div. If a
  133. * string, will be used as the HTML tag to use.
  134. * - `class` string The classname for the error message
  135. *
  136. * @param string $field A field name, like "Modelname.fieldname"
  137. * @param mixed $text Error message or array of $options. If array, `attributes` key
  138. * will get used as html attributes for error container
  139. * @param array $options Rendering options for <div /> wrapper tag
  140. * @return string If there are errors this method returns an error message, otherwise null.
  141. * @access public
  142. * @link http://book.cakephp.org/view/1423/error
  143. */
  144. public function error($field, $text = null, $options = array()) {
  145. $data = compact('field', 'text', 'options');
  146. $this->hook('form_error_alter', $data);
  147. extract($data);
  148. return $this->CoreForm->error($field, $text, $options);
  149. }
  150. /**
  151. * Returns a formatted LABEL element for HTML FORMs. Will automatically generate
  152. * a for attribute if one is not provided.
  153. *
  154. * @param string $fieldName This should be "Modelname.fieldname"
  155. * @param string $text Text that will appear in the label field.
  156. * @param mixed $options An array of HTML attributes, or a string, to be used as a class name.
  157. * @return string The formatted LABEL element
  158. * @link http://book.cakephp.org/view/1427/label
  159. */
  160. public function label($fieldName = null, $text = null, $options = array()) {
  161. $data = compact('fieldName', 'text', 'options');
  162. $this->hook('form_label_alter', $data);
  163. extract($data);
  164. return $this->CoreForm->label($fieldName, $text, $options);
  165. }
  166. /**
  167. * Generate a set of inputs for `$fields`. If $fields is null the current model
  168. * will be used.
  169. *
  170. * In addition to controller fields output, `$fields` can be used to control legend
  171. * and fieldset rendering with the `fieldset` and `legend` keys.
  172. * `$form->inputs(array('legend' => 'My legend'));` Would generate an input set with
  173. * a custom legend. You can customize individual inputs through `$fields` as well.
  174. *
  175. * {{{
  176. * $form->inputs(array(
  177. * 'name' => array('label' => 'custom label')
  178. * ));
  179. * }}}
  180. *
  181. * In addition to fields control, inputs() allows you to use a few additional options.
  182. *
  183. * - `fieldset` Set to false to disable the fieldset. If a string is supplied it will be used as
  184. * the classname for the fieldset element.
  185. * - `legend` Set to false to disable the legend for the generated input set. Or supply a string
  186. * to customize the legend text.
  187. *
  188. * @param mixed $fields An array of fields to generate inputs for, or null.
  189. * @param array $blacklist a simple array of fields to not create inputs for.
  190. * @return string Completed form inputs.
  191. */
  192. public function inputs($fields = null, $blacklist = null) {
  193. $data = compact('fields', 'blacklist');
  194. $this->hook('form_inputs_alter', $data);
  195. extract($data);
  196. return $this->CoreForm->inputs($fields, $blacklist);
  197. }
  198. /**
  199. * Generates a form input element complete with label and wrapper div
  200. *
  201. * ### Options
  202. *
  203. * See each field type method for more information. Any options that are part of
  204. * $attributes or $options for the different **type** methods can be included in `$options` for input().
  205. *
  206. * - `type` - Force the type of widget you want. e.g. `type => 'select'`
  207. * - `label` - Either a string label, or an array of options for the label. See FormHelper::label()
  208. * - `div` - Either `false` to disable the div, or an array of options for the div.
  209. * See HtmlHelper::div() for more options.
  210. * - `options` - for widgets that take options e.g. radio, select
  211. * - `error` - control the error message that is produced
  212. * - `empty` - String or boolean to enable empty select box options.
  213. * - `before` - Content to place before the label + input.
  214. * - `after` - Content to place after the label + input.
  215. * - `between` - Content to place between the label + input.
  216. * - `format` - format template for element order. Any element that is not in the array, will not be in the output.
  217. * - Default input format order: array('before', 'label', 'between', 'input', 'after', 'error')
  218. * - Default checkbox format order: array('before', 'input', 'between', 'label', 'after', 'error')
  219. * - Hidden input will not be formatted
  220. * - Radio buttons cannot have the order of input and label elements controlled with these settings.
  221. *
  222. * @param string $fieldName This should be "Modelname.fieldname"
  223. * @param array $options Each type of input takes different options.
  224. * @return string Completed form widget.
  225. * @access public
  226. * @link http://book.cakephp.org/view/1390/Automagic-Form-Elements
  227. */
  228. public function input($fieldName, $options = array()) {
  229. $data = compact('fieldName', 'options');
  230. $this->hook('form_input_alter', $data);
  231. if (isset($options['type'])) {
  232. $this->hook("form_{$options['type']}_alter", $data);
  233. }
  234. extract($data);
  235. return $this->CoreForm->input($fieldName, $options);
  236. }
  237. /**
  238. * Creates a checkbox input widget.
  239. *
  240. * ### Options:
  241. *
  242. * - `value` - the value of the checkbox
  243. * - `checked` - boolean indicate that this checkbox is checked.
  244. * - `hiddenField` - boolean to indicate if you want the results of checkbox() to include
  245. * a hidden input with a value of ''.
  246. * - `disabled` - create a disabled input.
  247. *
  248. * @param string $fieldName Name of a field, like this "Modelname.fieldname"
  249. * @param array $options Array of HTML attributes.
  250. * @return string An HTML text input element.
  251. * @access public
  252. * @link http://book.cakephp.org/view/1414/checkbox
  253. */
  254. public function checkbox($fieldName, $options = array()) {
  255. $data = compact('fieldName', 'options');
  256. $this->hook('form_checkbox_alter', $data);
  257. extract($data);
  258. return $this->CoreForm->checkbox($fieldName, $options);
  259. }
  260. /**
  261. * Creates a set of radio widgets. Will create a legend and fieldset
  262. * by default. Use $options to control this
  263. *
  264. * ### Attributes:
  265. *
  266. * - `separator` - define the string in between the radio buttons
  267. * - `legend` - control whether or not the widget set has a fieldset & legend
  268. * - `value` - indicate a value that is should be checked
  269. * - `label` - boolean to indicate whether or not labels for widgets show be displayed
  270. * - `hiddenField` - boolean to indicate if you want the results of radio() to include
  271. * a hidden input with a value of ''. This is useful for creating radio sets that non-continuous
  272. *
  273. * @param string $fieldName Name of a field, like this "Modelname.fieldname"
  274. * @param array $options Radio button options array.
  275. * @param array $attributes Array of HTML attributes, and special attributes above.
  276. * @return string Completed radio widget set.
  277. * @access public
  278. * @link http://book.cakephp.org/view/1429/radio
  279. */
  280. public function radio($fieldName, $options = array(), $attributes = array()) {
  281. $data = compact('fieldName', 'options', 'attributes');
  282. $this->hook('form_radio_alter', $data);
  283. extract($data);
  284. return $this->CoreForm->radio($fieldName, $options, $attributes);
  285. }
  286. /**
  287. * Creates a textarea widget.
  288. *
  289. * ### Options:
  290. *
  291. * - `escape` - Whether or not the contents of the textarea should be escaped. Defaults to true.
  292. *
  293. * @param string $fieldName Name of a field, in the form "Modelname.fieldname"
  294. * @param array $options Array of HTML attributes, and special options above.
  295. * @return string A generated HTML text input element
  296. * @access public
  297. * @link http://book.cakephp.org/view/1433/textarea
  298. */
  299. public function textarea($fieldName, $options = array()) {
  300. $data = compact('fieldName', 'options');
  301. $this->hook('form_textarea_alter', $data);
  302. extract($data);
  303. return $this->CoreForm->textarea($fieldName, $options);
  304. }
  305. /**
  306. * Creates a hidden input field.
  307. *
  308. * @param string $fieldName Name of a field, in the form of "Modelname.fieldname"
  309. * @param array $options Array of HTML attributes.
  310. * @return string A generated hidden input
  311. * @access public
  312. * @link http://book.cakephp.org/view/1425/hidden
  313. */
  314. public function hidden($fieldName, $options = array()) {
  315. $data = compact('fieldName', 'options');
  316. $this->hook('form_hidden_alter', $data);
  317. extract($data);
  318. return $this->CoreForm->hidden($fieldName, $options);
  319. }
  320. /**
  321. * Creates file input widget.
  322. *
  323. * @param string $fieldName Name of a field, in the form "Modelname.fieldname"
  324. * @param array $options Array of HTML attributes.
  325. * @return string A generated file input.
  326. * @access public
  327. * @link http://book.cakephp.org/view/1424/file
  328. */
  329. public function file($fieldName, $options = array()) {
  330. $data = compact('fieldName', 'options');
  331. $this->hook('form_file_alter', $data);
  332. extract($data);
  333. return $this->CoreForm->file($fieldName, $options);
  334. }
  335. /**
  336. * Creates a `<button>` tag. The type attribute defaults to `type="submit"`
  337. * You can change it to a different value by using `$options['type']`.
  338. *
  339. * ### Options:
  340. *
  341. * - `escape` - HTML entity encode the $title of the button. Defaults to false.
  342. *
  343. * @param string $title The button's caption. Not automatically HTML encoded
  344. * @param array $options Array of options and HTML attributes.
  345. * @return string A HTML button tag.
  346. * @access public
  347. * @link http://book.cakephp.org/view/1415/button
  348. */
  349. public function button($title, $options = array()) {
  350. $data = compact('title', 'options');
  351. $this->hook('form_button_alter', $data);
  352. extract($data);
  353. return $this->CoreForm->file($title, $options);
  354. }
  355. /**
  356. * Create a `<button>` tag with `<form>` using POST method.
  357. *
  358. * This method creates an element <form>. So do not use this method in some opened form.
  359. *
  360. * ### Options:
  361. *
  362. * - `data` - Array with key/value to pass in input hidden
  363. * - Other options is the same of button method.
  364. *
  365. * @param string $title The button's caption. Not automatically HTML encoded
  366. * @param mixed $url URL as string or array
  367. * @param array $options Array of options and HTML attributes.
  368. * @return string A HTML button tag.
  369. */
  370. public function postButton($title, $url, $options = array()) {
  371. $data = compact('title', 'url', 'options');
  372. $this->hook('form_post_button_alter', $data);
  373. extract($data);
  374. return $this->CoreForm->postButton($title, $url, $options);
  375. }
  376. /**
  377. * Creates an HTML link, but access the url using method POST. Requires javascript enabled in browser.
  378. *
  379. * This method creates an element <form>. So do not use this method in some opened form.
  380. *
  381. * ### Options:
  382. *
  383. * - `data` - Array with key/value to pass in input hidden
  384. * - Other options is the same of HtmlHelper::link() method.
  385. * - The option `onclick` will be replaced.
  386. *
  387. * @param string $title The content to be wrapped by <a> tags.
  388. * @param mixed $url Cake-relative URL or array of URL parameters, or external URL (starts with http://)
  389. * @param array $options Array of HTML attributes.
  390. * @param string $confirmMessage JavaScript confirmation message.
  391. * @return string An `<a />` element.
  392. */
  393. public function postLink($title, $url = null, $options = array(), $confirmMessage = false) {
  394. $data = compact('title', 'url', 'options', 'confirmMessage');
  395. $this->hook('form_post_link_alter', $data);
  396. extract($data);
  397. return $this->CoreForm->postLink($title, $url, $options, $confirmMessage);
  398. }
  399. /**
  400. * Creates a submit button element. This method will generate `<input />` elements that
  401. * can be used to submit, and reset forms by using $options. image submits can be created by supplying an
  402. * image path for $caption.
  403. *
  404. * ### Options
  405. *
  406. * - `div` - Include a wrapping div? Defaults to true. Accepts sub options similar to
  407. * FormHelper::input().
  408. * - `before` - Content to include before the input.
  409. * - `after` - Content to include after the input.
  410. * - `type` - Set to 'reset' for reset inputs. Defaults to 'submit'
  411. * - Other attributes will be assigned to the input element.
  412. *
  413. * ### Options
  414. *
  415. * - `div` - Include a wrapping div? Defaults to true. Accepts sub options similar to
  416. * FormHelper::input().
  417. * - Other attributes will be assigned to the input element.
  418. *
  419. * @param string $caption The label appearing on the button OR if string contains :// or the
  420. * extension .jpg, .jpe, .jpeg, .gif, .png use an image if the extension
  421. * exists, AND the first character is /, image is relative to webroot,
  422. * OR if the first character is not /, image is relative to webroot/img.
  423. * @param array $options Array of options. See above.
  424. * @return string A HTML submit button
  425. * @access public
  426. * @link http://book.cakephp.org/view/1431/submit
  427. */
  428. public function submit($caption = null, $options = array()) {
  429. $data = compact('caption', 'options');
  430. $this->hook('form_submit_alter', $data);
  431. extract($data);
  432. return $this->CoreForm->submit($caption, $options);
  433. }
  434. /**
  435. * Returns a formatted SELECT element.
  436. *
  437. * ### Attributes:
  438. *
  439. * - `showParents` - If included in the array and set to true, an additional option element
  440. * will be added for the parent of each option group. You can set an option with the same name
  441. * and it's key will be used for the value of the option.
  442. * - `multiple` - show a multiple select box. If set to 'checkbox' multiple checkboxes will be
  443. * created instead.
  444. * - `empty` - If true, the empty select option is shown. If a string,
  445. * that string is displayed as the empty element.
  446. * - `escape` - If true contents of options will be HTML entity encoded. Defaults to true.
  447. * - `value` The selected value of the input.
  448. * - `class` - When using multiple = checkbox the classname to apply to the divs. Defaults to 'checkbox'.
  449. *
  450. * ### Using options
  451. *
  452. * A simple array will create normal options:
  453. *
  454. * {{{
  455. * $options = array(1 => 'one', 2 => 'two);
  456. * $this->CoreForm->select('Model.field', $options));
  457. * }}}
  458. *
  459. * While a nested options array will create optgroups with options inside them.
  460. * {{{
  461. * $options = array(
  462. * 1 => 'bill',
  463. * 'fred' => array(
  464. * 2 => 'fred',
  465. * 3 => 'fred jr.'
  466. * )
  467. * );
  468. * $this->CoreForm->select('Model.field', $options);
  469. * }}}
  470. *
  471. * In the above `2 => 'fred'` will not generate an option element. You should enable the `showParents`
  472. * attribute to show the fred option.
  473. *
  474. * @param string $fieldName Name attribute of the SELECT
  475. * @param array $options Array of the OPTION elements (as 'value'=>'Text' pairs) to be used in the
  476. * SELECT element
  477. * @param array $attributes The HTML attributes of the select element.
  478. * @return string Formatted SELECT element
  479. * @access public
  480. * @link http://book.cakephp.org/view/1430/select
  481. */
  482. public function select($fieldName, $options = array(), $attributes = array()) {
  483. $data = compact('fieldName', 'options', 'attributes');
  484. $this->hook('form_select_alter', $data);
  485. extract($data);
  486. return $this->CoreForm->select($fieldName, $options, $attributes);
  487. }
  488. /**
  489. * Returns a SELECT element for days.
  490. *
  491. * ### Attributes:
  492. *
  493. * - `empty` - If true, the empty select option is shown. If a string,
  494. * that string is displayed as the empty element.
  495. * - `value` The selected value of the input.
  496. *
  497. * @param string $fieldName Prefix name for the SELECT element
  498. * @param array $attributes HTML attributes for the select element
  499. * @return string A generated day select box.
  500. * @access public
  501. * @link http://book.cakephp.org/view/1419/day
  502. */
  503. public function day($fieldName = null, $attributes = array()) {
  504. $data = compact('fieldName', 'attributes');
  505. $this->hook('form_day_alter', $data);
  506. extract($data);
  507. return $this->CoreForm->day($fieldName, $attributes);
  508. }
  509. /**
  510. * Returns a SELECT element for years
  511. *
  512. * ### Attributes:
  513. *
  514. * - `empty` - If true, the empty select option is shown. If a string,
  515. * that string is displayed as the empty element.
  516. * - `orderYear` - Ordering of year values in select options.
  517. * Possible values 'asc', 'desc'. Default 'desc'
  518. * - `value` The selected value of the input.
  519. *
  520. * @param string $fieldName Prefix name for the SELECT element
  521. * @param integer $minYear First year in sequence
  522. * @param integer $maxYear Last year in sequence
  523. * @param array $attributes Attribute array for the select elements.
  524. * @return string Completed year select input
  525. * @access public
  526. * @link http://book.cakephp.org/view/1416/year
  527. */
  528. public function year($fieldName, $minYear = null, $maxYear = null, $attributes = array()) {
  529. $data = compact('fieldName', 'minYear', 'maxYear', 'attributes');
  530. $this->hook('form_year_alter', $data);
  531. extract($data);
  532. return $this->CoreForm->year($fieldName, $minYear, $maxYear, $attributes);
  533. }
  534. /**
  535. * Returns a SELECT element for months.
  536. *
  537. * ### Attributes:
  538. *
  539. * - `monthNames` - If false, 2 digit numbers will be used instead of text.
  540. * If a array, the given array will be used.
  541. * - `empty` - If true, the empty select option is shown. If a string,
  542. * that string is displayed as the empty element.
  543. * - `value` The selected value of the input.
  544. *
  545. * @param string $fieldName Prefix name for the SELECT element
  546. * @param array $attributes Attributes for the select element
  547. * @return string A generated month select dropdown.
  548. * @access public
  549. * @link http://book.cakephp.org/view/1417/month
  550. */
  551. public function month($fieldName, $attributes = array()) {
  552. $data = compact('fieldName', 'attributes');
  553. $this->hook('form_month_alter', $data);
  554. extract($data);
  555. return $this->CoreForm->month($fieldName, $attributes);
  556. }
  557. /**
  558. * Returns a SELECT element for hours.
  559. *
  560. * ### Attributes:
  561. *
  562. * - `empty` - If true, the empty select option is shown. If a string,
  563. * that string is displayed as the empty element.
  564. * - `value` The selected value of the input.
  565. *
  566. * @param string $fieldName Prefix name for the SELECT element
  567. * @param boolean $format24Hours True for 24 hours format
  568. * @param array $attributes List of HTML attributes
  569. * @return string Completed hour select input
  570. * @access public
  571. * @link http://book.cakephp.org/view/1420/hour
  572. */
  573. public function hour($fieldName, $format24Hours = false, $attributes = array()) {
  574. $data = compact('fieldName', 'format24Hours', 'attributes');
  575. $this->hook('form_hour_alter', $data);
  576. extract($data);
  577. return $this->CoreForm->hour($fieldName, $format24Hours, $attributes);
  578. }
  579. /**
  580. * Returns a SELECT element for minutes.
  581. *
  582. * ### Attributes:
  583. *
  584. * - `empty` - If true, the empty select option is shown. If a string,
  585. * that string is displayed as the empty element.
  586. * - `value` The selected value of the input.
  587. *
  588. * @param string $fieldName Prefix name for the SELECT element
  589. * @param string $attributes Array of Attributes
  590. * @return string Completed minute select input.
  591. * @access public
  592. * @link http://book.cakephp.org/view/1421/minute
  593. */
  594. public function minute($fieldName, $attributes = array()) {
  595. $data = compact('fieldName', 'attributes');
  596. $this->hook('form_minute_alter', $data);
  597. extract($data);
  598. return $this->CoreForm->minute($fieldName, $attributes);
  599. }
  600. /**
  601. * Returns a SELECT element for AM or PM.
  602. *
  603. * ### Attributes:
  604. *
  605. * - `empty` - If true, the empty select option is shown. If a string,
  606. * that string is displayed as the empty element.
  607. * - `value` The selected value of the input.
  608. *
  609. * @param string $fieldName Prefix name for the SELECT element
  610. * @param string $attributes Array of Attributes
  611. * @param bool $showEmpty Show/Hide an empty option
  612. * @return string Completed meridian select input
  613. * @access public
  614. * @link http://book.cakephp.org/view/1422/meridian
  615. */
  616. public function meridian($fieldName, $attributes = array()) {
  617. $data = compact('fieldName', 'attributes');
  618. $this->hook('form_meridian_alter', $data);
  619. extract($data);
  620. return $this->CoreForm->meridian($fieldName, $attributes);
  621. }
  622. /**
  623. * Returns a set of SELECT elements for a full datetime setup: day, month and year, and then time.
  624. *
  625. * ### Attributes:
  626. *
  627. * - `monthNames` If false, 2 digit numbers will be used instead of text.
  628. * If a array, the given array will be used.
  629. * - `minYear` The lowest year to use in the year select
  630. * - `maxYear` The maximum year to use in the year select
  631. * - `interval` The interval for the minutes select. Defaults to 1
  632. * - `separator` The contents of the string between select elements. Defaults to '-'
  633. * - `empty` - If true, the empty select option is shown. If a string,
  634. * that string is displayed as the empty element.
  635. * - `value` | `default` The default value to be used by the input. A value in `$this->data`
  636. * matching the field name will override this value. If no default is provided `time()` will be used.
  637. *
  638. * @param string $fieldName Prefix name for the SELECT element
  639. * @param string $dateFormat DMY, MDY, YMD.
  640. * @param string $timeFormat 12, 24.
  641. * @param string $attributes array of Attributes
  642. * @return string Generated set of select boxes for the date and time formats chosen.
  643. * @access public
  644. * @link http://book.cakephp.org/view/1418/dateTime
  645. */
  646. public function dateTime($fieldName, $dateFormat = 'DMY', $timeFormat = '12', $attributes = array()) {
  647. $data = compact('fieldName', 'dateFormat', 'timeFormat', 'attributes');
  648. $this->hook('form_date_time_alter', $data);
  649. extract($data);
  650. return $this->CoreForm->dateTime($fieldName, $dateFormat, $timeFormat, $attributes);
  651. }
  652. /**
  653. * Add support for special HABTM syntax.
  654. *
  655. * Sets this helper's model and field properties to the dot-separated value-pair in $entity.
  656. *
  657. * @param mixed $entity A field name, like "ModelName.fieldName" or "ModelName.ID.fieldName"
  658. * @param boolean $setScope Sets the view scope to the model specified in $tagValue
  659. * @return void
  660. */
  661. public function setEntity($entity, $setScope = false) {
  662. $data = compact('entity', 'setScope');
  663. $this->hook('form_set_entity_alter', $data);
  664. extract($data);
  665. return $this->CoreForm->setEntity($entity, $setScope);
  666. }
  667. /**
  668. * Missing method handler - implements various simple input types. Is used to create inputs
  669. * of various types. e.g. `$this->Form->text();` will create `<input type="text" />` while
  670. * `$this->Form->range();` will create `<input type="range" />`
  671. *
  672. * ### Usage
  673. *
  674. * `$this->Form->search('User.query', array('value' => 'test'));`
  675. *
  676. * Will make an input like:
  677. *
  678. * `<input type="search" id="UserQuery" name="data[User][query]" value="test" />`
  679. *
  680. * The first argument to an input type should always be the fieldname, in `Model.field` format.
  681. * The second argument should always be an array of attributes for the input.
  682. *
  683. * @param string $method Method name / input type to make.
  684. * @param array $params Parameters for the method call
  685. * @return string Formatted input method.
  686. * @throws CakeException When there are no params for the method call.
  687. */
  688. public function __call($method, $params) {
  689. return $this->CoreForm->__call($method, $params);
  690. }
  691. }