Skip to content

Commit

Permalink
Making sure forms always have a generated id attribute. Updating tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Mar 16, 2011
1 parent 6fd5ff3 commit c6b7482
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions cake/libs/view/helpers/form.php
Expand Up @@ -238,11 +238,14 @@ function create($model = null, $options = array()) {
$options);
$this->_inputDefaults = $options['inputDefaults'];
unset($options['inputDefaults']);

if (!isset($options['id'])) {
$domId = isset($options['action']) ? $options['action'] : $this->request['action'];
$options['id'] = $this->domId($domId . 'Form');
}

if ($options['action'] === null && $options['url'] === null) {
$options['action'] = $this->request->here(false);
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) {
Expand All @@ -260,9 +263,6 @@ function create($model = null, $options = array()) {
'controller' => $this->_View->viewPath,
'action' => $options['action'],
);
if (!empty($options['action']) && !isset($options['id'])) {
$options['id'] = $this->domId($options['action'] . 'Form');
}
$options['action'] = array_merge($actionDefaults, (array)$options['url']);
if (empty($options['action'][0]) && !empty($id)) {
$options['action'][0] = $id;
Expand Down
6 changes: 3 additions & 3 deletions cake/tests/cases/libs/view/helpers/form.test.php
Expand Up @@ -723,7 +723,7 @@ function testCreateWithSecurity() {
$encoding = strtolower(Configure::read('App.encoding'));
$result = $this->Form->create('Contact', array('url' => '/contacts/add'));
$expected = array(
'form' => array('method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding),
'form' => array('method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding, 'id' => 'ContactAddForm'),
'div' => array('style' => 'display:none;'),
array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
array('input' => array(
Expand Down Expand Up @@ -1104,7 +1104,7 @@ function testFormSecuredInput() {
$result = $this->Form->create('Contact', array('url' => '/contacts/add'));
$encoding = strtolower(Configure::read('App.encoding'));
$expected = array(
'form' => array('method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding),
'form' => array('method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding, 'id' => 'ContactAddForm'),
'div' => array('style' => 'display:none;'),
array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
array('input' => array(
Expand Down Expand Up @@ -5659,7 +5659,7 @@ function testCreate() {

$result = $this->Form->create('User', array('url' => '/users/login'));
$expected = array(
'form' => array('method' => 'post', 'action' => '/users/login','accept-charset' => $encoding),
'form' => array('method' => 'post', 'action' => '/users/login', 'accept-charset' => $encoding, 'id' => 'UserAddForm'),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
Expand Down

0 comments on commit c6b7482

Please sign in to comment.