Skip to content

Commit

Permalink
Deprecate action in Form::create()
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Scherer committed Jan 4, 2016
1 parent 0aa8847 commit a2ce6c8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
10 changes: 5 additions & 5 deletions lib/Cake/Test/Case/View/Helper/FormHelperTest.php
Expand Up @@ -1780,7 +1780,7 @@ public function testFormValidationAssociated() {
$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(
Expand Down Expand Up @@ -1822,7 +1822,7 @@ public function testFormValidationAssociatedFirstLevel() {
$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),
Expand Down Expand Up @@ -1875,7 +1875,7 @@ public function testFormValidationAssociatedSecondLevel() {
$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),
Expand Down Expand Up @@ -8688,7 +8688,7 @@ public function testCreateCustomRoute() {
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',
Expand Down Expand Up @@ -8760,7 +8760,7 @@ public function testCreateWithInputDefaults() {
*/
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(
Expand Down
12 changes: 8 additions & 4 deletions lib/Cake/View/Helper/FormHelper.php
Expand Up @@ -312,19 +312,19 @@ public function tagIsInvalid() {
* ### 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.
Expand Down Expand Up @@ -379,6 +379,10 @@ public function create($model = null, $options = array()) {
$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');
Expand Down

0 comments on commit a2ce6c8

Please sign in to comment.