mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Add form attribute to hidden inputs when present.
If inputs are placed outside of the form elements the form attribute needs to be set on the hidden inputs. Without this attribute the empty state does not submit correctly. Fixes #3053
This commit is contained in:
parent
23350eb89e
commit
ee895a8bb1
2 changed files with 28 additions and 12 deletions
|
@ -3614,18 +3614,22 @@ class FormHelperTest extends CakeTestCase {
|
|||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Form->radio('Employee.gender', array('male' => 'Male', 'female' => 'Female'));
|
||||
$result = $this->Form->radio(
|
||||
'Employee.gender',
|
||||
array('male' => 'Male', 'female' => 'Female'),
|
||||
array('form' => 'my-form')
|
||||
);
|
||||
$expected = array(
|
||||
'fieldset' => array(),
|
||||
'legend' => array(),
|
||||
'Gender',
|
||||
'/legend',
|
||||
'input' => array('type' => 'hidden', 'name' => 'data[Employee][gender]', 'value' => '', 'id' => 'EmployeeGender_'),
|
||||
array('input' => array('type' => 'radio', 'name' => 'data[Employee][gender]', 'value' => 'male', 'id' => 'EmployeeGenderMale')),
|
||||
'input' => array('type' => 'hidden', 'name' => 'data[Employee][gender]', 'value' => '', 'id' => 'EmployeeGender_', 'form' => 'my-form'),
|
||||
array('input' => array('type' => 'radio', 'name' => 'data[Employee][gender]', 'value' => 'male', 'id' => 'EmployeeGenderMale', 'form' => 'my-form')),
|
||||
array('label' => array('for' => 'EmployeeGenderMale')),
|
||||
'Male',
|
||||
'/label',
|
||||
array('input' => array('type' => 'radio', 'name' => 'data[Employee][gender]', 'value' => 'female', 'id' => 'EmployeeGenderFemale')),
|
||||
array('input' => array('type' => 'radio', 'name' => 'data[Employee][gender]', 'value' => 'female', 'id' => 'EmployeeGenderFemale', 'form' => 'my-form')),
|
||||
array('label' => array('for' => 'EmployeeGenderFemale')),
|
||||
'Female',
|
||||
'/label',
|
||||
|
@ -4650,15 +4654,18 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Form->select(
|
||||
'Model.multi_field', $options, array('multiple' => 'multiple')
|
||||
'Model.multi_field', $options, array('form' => 'my-form', 'multiple' => 'multiple')
|
||||
);
|
||||
$expected = array(
|
||||
'input' => array(
|
||||
'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField_'
|
||||
'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField_',
|
||||
'form' => 'my-form',
|
||||
),
|
||||
'select' => array(
|
||||
'name' => 'data[Model][multi_field][]',
|
||||
'id' => 'ModelMultiField', 'multiple' => 'multiple'
|
||||
'id' => 'ModelMultiField',
|
||||
'multiple' => 'multiple',
|
||||
'form' => 'my-form',
|
||||
),
|
||||
array('option' => array('value' => '0')),
|
||||
'first',
|
||||
|
@ -5674,10 +5681,14 @@ class FormHelperTest extends CakeTestCase {
|
|||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Form->checkbox('Model.field', array('id' => 'theID', 'value' => 'myvalue'));
|
||||
$result = $this->Form->checkbox('Model.field', array(
|
||||
'id' => 'theID',
|
||||
'value' => 'myvalue',
|
||||
'form' => 'my-form',
|
||||
));
|
||||
$expected = array(
|
||||
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'theID_'),
|
||||
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => 'myvalue', 'id' => 'theID'))
|
||||
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'theID_', 'form' => 'my-form'),
|
||||
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => 'myvalue', 'id' => 'theID', 'form' => 'my-form'))
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
|
|
|
@ -1418,7 +1418,8 @@ class FormHelper extends AppHelper {
|
|||
'id' => $options['id'] . '_',
|
||||
'name' => $options['name'],
|
||||
'value' => ($options['hiddenField'] !== true ? $options['hiddenField'] : '0'),
|
||||
'secure' => false
|
||||
'form' => isset($options['form']) ? $options['form'] : null,
|
||||
'secure' => false,
|
||||
);
|
||||
if (isset($options['disabled']) && $options['disabled']) {
|
||||
$hiddenOptions['disabled'] = 'disabled';
|
||||
|
@ -1544,7 +1545,10 @@ class FormHelper extends AppHelper {
|
|||
if ($hiddenField) {
|
||||
if (!isset($value) || $value === '') {
|
||||
$hidden = $this->hidden($fieldName, array(
|
||||
'id' => $attributes['id'] . '_', 'value' => '', 'name' => $attributes['name']
|
||||
'form' => isset($attributes['form']) ? $attributes['form'] : null,
|
||||
'id' => $attributes['id'] . '_',
|
||||
'value' => '',
|
||||
'name' => $attributes['name']
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -2008,6 +2012,7 @@ class FormHelper extends AppHelper {
|
|||
'value' => '',
|
||||
'id' => $attributes['id'] . ($style ? '' : '_'),
|
||||
'secure' => false,
|
||||
'form' => isset($attributes['form']) ? $attributes['form'] : null,
|
||||
'name' => $attributes['name']
|
||||
);
|
||||
$select[] = $this->hidden(null, $hiddenAttributes);
|
||||
|
|
Loading…
Reference in a new issue