Deprecate action in Form::create()

This commit is contained in:
Mark Scherer 2016-01-04 14:22:40 +01:00
parent 0aa8847762
commit a2ce6c8c1f
2 changed files with 13 additions and 9 deletions

View file

@ -1780,7 +1780,7 @@ class FormHelperTest extends CakeTestCase {
$this->assertFalse(empty($result));
$this->assertFalse($this->UserForm->OpenidUrl->validates());
$result = $this->Form->create('UserForm', array('type' => 'post', 'action' => 'login'));
$result = $this->Form->create('UserForm', array('type' => 'post', 'url' => array('action' => 'login')));
$encoding = strtolower(Configure::read('App.encoding'));
$expected = array(
'form' => array(
@ -1822,7 +1822,7 @@ class FormHelperTest extends CakeTestCase {
$this->assertFalse($this->ValidateUser->validates());
$this->assertFalse($this->ValidateUser->ValidateProfile->validates());
$result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add'));
$result = $this->Form->create('ValidateUser', array('type' => 'post', 'url' => array('action' => 'add')));
$encoding = strtolower(Configure::read('App.encoding'));
$expected = array(
'form' => array('method' => 'post', 'action' => '/validate_users/add', 'id', 'accept-charset' => $encoding),
@ -1875,7 +1875,7 @@ class FormHelperTest extends CakeTestCase {
$this->assertFalse($this->ValidateUser->ValidateProfile->validates());
$this->assertFalse($this->ValidateUser->ValidateProfile->ValidateItem->validates());
$result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add'));
$result = $this->Form->create('ValidateUser', array('type' => 'post', 'url' => array('action' => 'add')));
$encoding = strtolower(Configure::read('App.encoding'));
$expected = array(
'form' => array('method' => 'post', 'action' => '/validate_users/add', 'id', 'accept-charset' => $encoding),
@ -8688,7 +8688,7 @@ class FormHelperTest extends CakeTestCase {
Router::connect('/login', array('controller' => 'users', 'action' => 'login'));
$encoding = strtolower(Configure::read('App.encoding'));
$result = $this->Form->create('User', array('action' => 'login'));
$result = $this->Form->create('User', array('url' => array('action' => 'login')));
$expected = array(
'form' => array(
'id' => 'UserLoginForm', 'method' => 'post', 'action' => '/login',
@ -8760,7 +8760,7 @@ class FormHelperTest extends CakeTestCase {
*/
public function testCreateWithAcceptCharset() {
$result = $this->Form->create('UserForm', array(
'type' => 'post', 'action' => 'login', 'encoding' => 'iso-8859-1'
'type' => 'post', 'url' => array('action' => 'login'), 'encoding' => 'iso-8859-1'
)
);
$expected = array(

View file

@ -312,19 +312,19 @@ class FormHelper extends AppHelper {
* ### Options:
*
* - `type` Form method defaults to POST
* - `action` The controller action the form submits to, (optional).
* - `action` The controller action the form submits to, (optional). Deprecated since 2.8, use `url`.
* - `url` The URL the form submits to. Can be a string or a URL array. If you use 'url'
* you should leave 'action' undefined.
* - `default` Allows for the creation of Ajax forms. Set this to false to prevent the default event handler.
* - `default` Allows for the creation of AJAX forms. Set this to false to prevent the default event handler.
* Will create an onsubmit attribute if it doesn't not exist. If it does, default action suppression
* will be appended.
* - `onsubmit` Used in conjunction with 'default' to create ajax forms.
* - `onsubmit` Used in conjunction with 'default' to create AJAX forms.
* - `inputDefaults` set the default $options for FormHelper::input(). Any options that would
* be set when using FormHelper::input() can be set here. Options set with `inputDefaults`
* can be overridden when calling input()
* - `encoding` Set the accept-charset encoding for the form. Defaults to `Configure::read('App.encoding')`
*
* @param mixed $model The model name for which the form is being defined. Should
* @param mixed|null $model The model name for which the form is being defined. Should
* include the plugin name for plugin models. e.g. `ContactManager.Contact`.
* If an array is passed and $options argument is empty, the array will be used as options.
* If `false` no model is used.
@ -379,6 +379,10 @@ class FormHelper extends AppHelper {
$this->inputDefaults($options['inputDefaults']);
unset($options['inputDefaults']);
if (isset($options['action'])) {
trigger_error('Using key `action` is deprecated, use `url` directly instead.', E_USER_DEPRECATED);
}
if (!isset($options['id'])) {
$domId = isset($options['action']) ? $options['action'] : $this->request['action'];
$options['id'] = $this->domId($domId . 'Form');