Skip to content

Commit 9f23f65

Browse files
ceerambar
authored andcommitted
Passing empty string in [\'error\'] behaved like false, now will behave like any other string
1 parent d489d49 commit 9f23f65

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

cake/libs/view/helpers/form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ function error($field, $text = null, $options = array()) {
512512
unset($options[$error]);
513513
}
514514

515-
if ($text != null) {
515+
if ($text !== null) {
516516
$error = $text;
517517
} elseif (is_numeric($error)) {
518518
$error = sprintf(__('Error in field %s', true), Inflector::humanize($this->field()));

cake/tests/cases/libs/view/helpers/form.test.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,34 @@ function testPasswordValidation() {
13251325
$this->assertTags($result, $expected);
13261326
}
13271327

1328+
/**
1329+
* testEmptyErrorValidation method
1330+
*
1331+
* test validation error div
1332+
*
1333+
* @access public
1334+
* @return void
1335+
*/
1336+
function testEmptyErrorValidation() {
1337+
$this->Form->validationErrors['Contact']['password'] = 'Please provide a password';
1338+
$result = $this->Form->input('Contact.password', array('error' => ''));
1339+
$expected = array(
1340+
'div' => array('class' => 'input password error'),
1341+
'label' => array('for' => 'ContactPassword'),
1342+
'Password',
1343+
'/label',
1344+
'input' => array(
1345+
'type' => 'password', 'name' => 'data[Contact][password]',
1346+
'id' => 'ContactPassword', 'class' => 'form-error'
1347+
),
1348+
array('div' => array('class' => 'error-message')),
1349+
array(),
1350+
'/div',
1351+
'/div'
1352+
);
1353+
$this->assertTags($result, $expected);
1354+
}
1355+
13281356
/**
13291357
* testFormValidationAssociated method
13301358
*
@@ -5804,7 +5832,7 @@ public function testCreateOnSubmit() {
58045832

58055833
$expected = array(
58065834
'form' => array(
5807-
'id' => 'ContactAddForm', 'method' => 'post',
5835+
'id' => 'ContactAddForm', 'method' => 'post',
58085836
'onsubmit' => 'someFunction();event.returnValue = false; return false;',
58095837
'action' => '/contacts/index/param',
58105838
'accept-charset' => 'utf-8'

0 commit comments

Comments
 (0)