From c6b74823088841fd39e41fa7ef81199eea227cd8 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 15 Mar 2011 21:19:15 -0400 Subject: [PATCH] Making sure forms always have a generated id attribute. Updating tests. --- cake/libs/view/helpers/form.php | 12 ++++++------ cake/tests/cases/libs/view/helpers/form.test.php | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 00ec1235101..a6bbe254068 100644 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -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) { @@ -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; diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index d8ccbf6173b..f1a2debd485 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -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( @@ -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( @@ -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'