|
|
@@ -805,42 +805,43 @@ class FormHelper extends AppHelper {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Generate a set of inputs for `$fields`. If $fields is null the current model
|
|
|
+ * Generate a set of inputs for `$fields`. If $fields is null the fields of current model
|
|
|
* will be used.
|
|
|
*
|
|
|
- * In addition to controller fields output, `$fields` can be used to control legend
|
|
|
- * and fieldset rendering with the `fieldset` and `legend` keys.
|
|
|
- * `$form->inputs(array('legend' => 'My legend'));` Would generate an input set with
|
|
|
- * a custom legend. You can customize individual inputs through `$fields` as well.
|
|
|
- *
|
|
|
+ * You can customize individual inputs through `$fields`.
|
|
|
* {{{
|
|
|
- * $form->inputs(array(
|
|
|
+ * $this->Form->inputs(array(
|
|
|
* 'name' => array('label' => 'custom label')
|
|
|
* ));
|
|
|
* }}}
|
|
|
*
|
|
|
- * In addition to fields control, inputs() allows you to use a few additional options.
|
|
|
+ * In addition to controller fields output, `$fields` can be used to control legend
|
|
|
+ * and fieldset rendering.
|
|
|
+ * `$this->Form->inputs('My legend');` Would generate an input set with a custom legend.
|
|
|
+ * Passing `fieldset` and `legend` key in `$fields` array has been deprecated since 2.3,
|
|
|
+ * for more fine grained control use the `fieldset` and `legend` keys in `$options` param.
|
|
|
*
|
|
|
+ * @param array $fields An array of fields to generate inputs for, or null.
|
|
|
+ * @param array $blacklist A simple array of fields to not create inputs for.
|
|
|
+ * @param array $options Options array. Valid keys are:
|
|
|
* - `fieldset` Set to false to disable the fieldset. If a string is supplied it will be used as
|
|
|
* the classname for the fieldset element.
|
|
|
* - `legend` Set to false to disable the legend for the generated input set. Or supply a string
|
|
|
* to customize the legend text.
|
|
|
- *
|
|
|
- * @param array $fields An array of fields to generate inputs for, or null.
|
|
|
- * @param array $blacklist a simple array of fields to not create inputs for.
|
|
|
* @return string Completed form inputs.
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::inputs
|
|
|
*/
|
|
|
- public function inputs($fields = null, $blacklist = null) {
|
|
|
+ public function inputs($fields = null, $blacklist = null, $options = array()) {
|
|
|
$fieldset = $legend = true;
|
|
|
$model = $this->model();
|
|
|
+ $modelFields = array_keys($this->_introspectModel($model, 'fields'));
|
|
|
if (is_array($fields)) {
|
|
|
- if (array_key_exists('legend', $fields)) {
|
|
|
+ if (array_key_exists('legend', $fields) && !in_array('legend', $modelFields)) {
|
|
|
$legend = $fields['legend'];
|
|
|
unset($fields['legend']);
|
|
|
}
|
|
|
|
|
|
- if (isset($fields['fieldset'])) {
|
|
|
+ if (isset($fields['fieldset']) && !in_array('fieldset', $modelFields)) {
|
|
|
$fieldset = $fields['fieldset'];
|
|
|
unset($fields['fieldset']);
|
|
|
}
|
|
|
@@ -852,8 +853,15 @@ class FormHelper extends AppHelper {
|
|
|
$fields = array();
|
|
|
}
|
|
|
|
|
|
+ if (isset($options['legend'])) {
|
|
|
+ $legend = $options['legend'];
|
|
|
+ }
|
|
|
+ if (isset($options['fieldset'])) {
|
|
|
+ $fieldset = $options['fieldset'];
|
|
|
+ }
|
|
|
+
|
|
|
if (empty($fields)) {
|
|
|
- $fields = array_keys($this->_introspectModel($model, 'fields'));
|
|
|
+ $fields = $modelFields;
|
|
|
}
|
|
|
|
|
|
if ($legend === true) {
|
|
|
@@ -892,13 +900,13 @@ class FormHelper extends AppHelper {
|
|
|
$fieldsetClass = '';
|
|
|
}
|
|
|
|
|
|
- if ($fieldset && $legend) {
|
|
|
- return $this->Html->useTag('fieldset', $fieldsetClass, $this->Html->useTag('legend', $legend) . $out);
|
|
|
- } elseif ($fieldset) {
|
|
|
- return $this->Html->useTag('fieldset', $fieldsetClass, $out);
|
|
|
- } else {
|
|
|
- return $out;
|
|
|
+ if ($fieldset) {
|
|
|
+ if ($legend) {
|
|
|
+ $out = $this->Html->useTag('legend', $legend) . $out;
|
|
|
+ }
|
|
|
+ $out = $this->Html->useTag('fieldset', $fieldsetClass, $out);
|
|
|
}
|
|
|
+ return $out;
|
|
|
}
|
|
|
|
|
|
/**
|