mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Made form post to the current location by default. Fixes #1418
This commit is contained in:
parent
2977448891
commit
06f9fc0fc9
2 changed files with 39 additions and 4 deletions
|
@ -238,8 +238,12 @@ class FormHelper extends AppHelper {
|
|||
$options);
|
||||
$this->_inputDefaults = $options['inputDefaults'];
|
||||
unset($options['inputDefaults']);
|
||||
|
||||
if (empty($options['url']) || is_array($options['url'])) {
|
||||
if ($options['action'] === null && $options['url'] === null) {
|
||||
$options['action'] = $this->request->here;
|
||||
if (!isset($options['id'])) {
|
||||
$options['id'] = $this->domId($this->request['action'] . 'Form');
|
||||
}
|
||||
} elseif (empty($options['url']) || is_array($options['url'])) {
|
||||
if (empty($options['url']['controller'])) {
|
||||
if (!empty($model) && $model != $this->defaultModel) {
|
||||
$options['url']['controller'] = Inflector::underscore(Inflector::pluralize($model));
|
||||
|
|
|
@ -670,6 +670,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->Form = new FormHelper($this->View);
|
||||
$this->Form->Html = new HtmlHelper($this->View);
|
||||
$this->Form->request = new CakeRequest(null, false);
|
||||
$this->Form->request->here = '/contacts/add';
|
||||
$this->Form->request['action'] = 'add';
|
||||
$this->Form->request->webroot = '';
|
||||
$this->Form->request->base = '';
|
||||
|
@ -5524,6 +5525,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertTags($result, $expected);
|
||||
|
||||
$this->Form->request->data['Contact']['id'] = 1;
|
||||
$this->Form->request->here = '/contacts/edit/1';
|
||||
$this->Form->request['action'] = 'edit';
|
||||
$result = $this->Form->create('Contact');
|
||||
$expected = array(
|
||||
|
@ -5538,6 +5540,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertTags($result, $expected);
|
||||
|
||||
$this->Form->request->data['Contact']['id'] = 1;
|
||||
$this->Form->request->here = '/contacts/edit/1';
|
||||
$this->Form->request['action'] = 'edit';
|
||||
$result = $this->Form->create('Contact', array('type' => 'file'));
|
||||
$expected = array(
|
||||
|
@ -5552,7 +5555,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertTags($result, $expected);
|
||||
|
||||
$this->Form->request->data['ContactNonStandardPk']['pk'] = 1;
|
||||
$result = $this->Form->create('ContactNonStandardPk');
|
||||
$result = $this->Form->create('ContactNonStandardPk', array('url' => array('action' => 'edit')));
|
||||
$expected = array(
|
||||
'form' => array(
|
||||
'id' => 'ContactNonStandardPkEditForm', 'method' => 'post',
|
||||
|
@ -5638,6 +5641,33 @@ class FormHelperTest extends CakeTestCase {
|
|||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$this->Form->request->here = '/contacts/add/Contact:1';
|
||||
$result = $this->Form->create();
|
||||
$expected = array(
|
||||
'form' => array(
|
||||
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/Contact:1',
|
||||
'accept-charset' => 'utf-8'
|
||||
),
|
||||
'div' => array('style' => 'display:none;'),
|
||||
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$this->Form->request['action'] = 'delete';
|
||||
$this->Form->request->here = '/contacts/delete/10/User:42';
|
||||
$result = $this->Form->create();
|
||||
$expected = array(
|
||||
'form' => array(
|
||||
'id' => 'ContactDeleteForm', 'method' => 'post', 'action' => '/contacts/delete/10/User:42',
|
||||
'accept-charset' => 'utf-8'
|
||||
),
|
||||
'div' => array('style' => 'display:none;'),
|
||||
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5809,7 +5839,8 @@ class FormHelperTest extends CakeTestCase {
|
|||
*/
|
||||
function testGetFormWithFalseModel() {
|
||||
$encoding = strtolower(Configure::read('App.encoding'));
|
||||
$result = $this->Form->create(false, array('type' => 'get'));
|
||||
$this->Form->request['controller'] = 'contact_test';
|
||||
$result = $this->Form->create(false, array('type' => 'get', 'url' => array('controller' => 'contact_test')));
|
||||
|
||||
$expected = array('form' => array(
|
||||
'id' => 'addForm', 'method' => 'get', 'action' => '/contact_test/add',
|
||||
|
|
Loading…
Reference in a new issue