mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Making submit() and button() create unlocked fields by default.
This fixes issues where buttons would cause post validation checks to fail. Fixes #1746
This commit is contained in:
parent
878b854be0
commit
613410f985
2 changed files with 40 additions and 3 deletions
|
@ -949,7 +949,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
)),
|
)),
|
||||||
array('input' => array(
|
array('input' => array(
|
||||||
'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
|
'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
|
||||||
'value' => '', 'id' => 'preg:/TokenUnlocked\d+/'
|
'value' => 'cancel%7Csave', 'id' => 'preg:/TokenUnlocked\d+/'
|
||||||
)),
|
)),
|
||||||
'/div'
|
'/div'
|
||||||
);
|
);
|
||||||
|
@ -5572,6 +5572,20 @@ class FormHelperTest extends CakeTestCase {
|
||||||
$this->assertNoPattern('/\&039/', $result);
|
$this->assertNoPattern('/\&039/', $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that button() makes unlocked fields by default.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testButtonUnlockedByDefault() {
|
||||||
|
$this->Form->request->params['_Token']['key'] = 'secured';
|
||||||
|
$this->Form->button('Save', array('name' => 'save'));
|
||||||
|
$this->Form->button('Clear');
|
||||||
|
|
||||||
|
$result = $this->Form->unlockField();
|
||||||
|
$this->assertEquals(array('save'), $result);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testPostButton method
|
* testPostButton method
|
||||||
*
|
*
|
||||||
|
@ -5811,6 +5825,21 @@ class FormHelperTest extends CakeTestCase {
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Submit buttons should be unlocked by default as there could be multiples, and only one will
|
||||||
|
* be submitted at a time.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testSubmitUnlockedByDefault() {
|
||||||
|
$this->Form->request->params['_Token']['key'] = 'secured';
|
||||||
|
$this->Form->submit('Go go');
|
||||||
|
$this->Form->submit('Save', array('name' => 'save'));
|
||||||
|
|
||||||
|
$result = $this->Form->unlockField();
|
||||||
|
$this->assertEquals(array('save'), $result, 'Only submits with name attributes should be unlocked.');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test the create() method
|
* test the create() method
|
||||||
*
|
*
|
||||||
|
|
|
@ -1344,10 +1344,13 @@ class FormHelper extends AppHelper {
|
||||||
* @link http://book.cakephp.org/view/1415/button
|
* @link http://book.cakephp.org/view/1415/button
|
||||||
*/
|
*/
|
||||||
public function button($title, $options = array()) {
|
public function button($title, $options = array()) {
|
||||||
$options += array('type' => 'submit', 'escape' => false);
|
$options += array('type' => 'submit', 'escape' => false, 'secure' => false);
|
||||||
if ($options['escape']) {
|
if ($options['escape']) {
|
||||||
$title = h($title);
|
$title = h($title);
|
||||||
}
|
}
|
||||||
|
if (isset($options['name'])) {
|
||||||
|
$this->__secure($options['secure'], $options['name']);
|
||||||
|
}
|
||||||
return $this->Html->useTag('button', $options['type'], array_diff_key($options, array('type' => '')), $title);
|
return $this->Html->useTag('button', $options['type'], array_diff_key($options, array('type' => '')), $title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1470,7 +1473,7 @@ class FormHelper extends AppHelper {
|
||||||
$div = $options['div'];
|
$div = $options['div'];
|
||||||
unset($options['div']);
|
unset($options['div']);
|
||||||
}
|
}
|
||||||
$options += array('type' => 'submit', 'before' => null, 'after' => null);
|
$options += array('type' => 'submit', 'before' => null, 'after' => null, 'secure' => false);
|
||||||
$divOptions = array('tag' => 'div');
|
$divOptions = array('tag' => 'div');
|
||||||
|
|
||||||
if ($div === true) {
|
if ($div === true) {
|
||||||
|
@ -1483,6 +1486,11 @@ class FormHelper extends AppHelper {
|
||||||
$divOptions = array_merge(array('class' => 'submit', 'tag' => 'div'), $div);
|
$divOptions = array_merge(array('class' => 'submit', 'tag' => 'div'), $div);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($options['name'])) {
|
||||||
|
$this->__secure($options['secure'], $options['name']);
|
||||||
|
}
|
||||||
|
unset($options['secure']);
|
||||||
|
|
||||||
$before = $options['before'];
|
$before = $options['before'];
|
||||||
$after = $options['after'];
|
$after = $options['after'];
|
||||||
unset($options['before'], $options['after']);
|
unset($options['before'], $options['after']);
|
||||||
|
|
Loading…
Reference in a new issue