mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
updating FormHelper to use fieldset instead of p. Inline styles are still used on these elements. We are not promoting the use of inline style, merely attempting to make life easier. Also, this adds a fieldset to multiple checkboxes if there is a group and also wraps the multiple checkboxes in divs and provides proper label for and input id attributes. also some changes to generic css to handle markup. Closes #3703
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6142 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
b6b2696488
commit
98859c8c72
4 changed files with 77 additions and 37 deletions
|
@ -220,9 +220,19 @@ fieldset legend {
|
|||
font-size: 160%;
|
||||
font-weight: bold;
|
||||
}
|
||||
fieldset fieldset {
|
||||
margin-top: 0px;
|
||||
margin-bottom: 20px;
|
||||
padding: 16px 0;
|
||||
}
|
||||
fieldset fieldset legend {
|
||||
font-size: 120%;
|
||||
font-weight: normal;
|
||||
margin-left: 20px;
|
||||
}
|
||||
fieldset fieldset div {
|
||||
clear: left;
|
||||
margin: 0 20px;
|
||||
}
|
||||
form div {
|
||||
clear: both;
|
||||
|
|
|
@ -221,9 +221,19 @@ fieldset legend {
|
|||
font-size: 160%;
|
||||
font-weight: bold;
|
||||
}
|
||||
fieldset fieldset {
|
||||
margin-top: 0px;
|
||||
margin-bottom: 20px;
|
||||
padding: 16px 0;
|
||||
}
|
||||
fieldset fieldset legend {
|
||||
font-size: 120%;
|
||||
font-weight: normal;
|
||||
margin-left: 20px;
|
||||
}
|
||||
fieldset fieldset div {
|
||||
clear: left;
|
||||
margin: 0 20px;
|
||||
}
|
||||
form div {
|
||||
clear: both;
|
||||
|
|
|
@ -203,9 +203,11 @@ class FormHelper extends AppHelper {
|
|||
$htmlAttributes = array_merge($options, $htmlAttributes);
|
||||
|
||||
if (isset($this->params['_Token']) && !empty($this->params['_Token'])) {
|
||||
$append .= '<p style="display: none;">';
|
||||
$append .= $this->hidden('_Token.key', array('value' => $this->params['_Token']['key'], 'id' => 'Token' . mt_rand()));
|
||||
$append .= '</p>';
|
||||
}
|
||||
|
||||
if (!empty($append)) {
|
||||
$append = '<fieldset style="display:none;">'.$append.'</fieldset>';
|
||||
}
|
||||
|
||||
$this->setEntity($model . '.', true);
|
||||
|
@ -271,7 +273,7 @@ class FormHelper extends AppHelper {
|
|||
*/
|
||||
function secure($fields) {
|
||||
if (!empty($fields)) {
|
||||
$append = '<p style="display: none;">';
|
||||
$append = '<fieldset style="display:none;">';
|
||||
|
||||
foreach ($fields as $key => $value) {
|
||||
if (strpos($key, '_') !== 0) {
|
||||
|
@ -285,7 +287,7 @@ class FormHelper extends AppHelper {
|
|||
}
|
||||
ksort($fields);
|
||||
$append .= $this->hidden('_Token.fields', array('value' => urlencode(Security::hash(serialize($fields) . Configure::read('Security.salt'))), 'id' => 'TokenFields' . mt_rand()));
|
||||
$append .= '</p>';
|
||||
$append .= '</fieldset>';
|
||||
return $append;
|
||||
}
|
||||
return null;
|
||||
|
@ -1421,12 +1423,20 @@ class FormHelper extends AppHelper {
|
|||
$htmlOptions = array();
|
||||
if (is_array($title) && (!isset($title['name']) || !isset($title['value']))) {
|
||||
if (!empty($name)) {
|
||||
$select[] = $this->Html->tags['optiongroupend'];
|
||||
if ($attributes['style'] === 'checkbox') {
|
||||
$select[] = $this->Html->tags['fieldsetend'];
|
||||
} else{
|
||||
$select[] = $this->Html->tags['optiongroupend'];
|
||||
}
|
||||
$parents[] = $name;
|
||||
}
|
||||
$select = array_merge($select, $this->__selectOptions($title, $selected, $parents, $showParents, $attributes));
|
||||
if (!empty($name)) {
|
||||
$select[] = sprintf($this->Html->tags['optiongroup'], $name, '');
|
||||
if ($attributes['style'] === 'checkbox') {
|
||||
$select[] = sprintf($this->Html->tags['fieldsetstart'], $name);
|
||||
} else{
|
||||
$select[] = sprintf($this->Html->tags['optiongroup'], $name, '');
|
||||
}
|
||||
}
|
||||
$name = null;
|
||||
} elseif (is_array($title)) {
|
||||
|
@ -1443,17 +1453,27 @@ class FormHelper extends AppHelper {
|
|||
$htmlOptions['selected'] = 'selected';
|
||||
}
|
||||
}
|
||||
|
||||
if ($showParents || (!in_array($title, $parents))) {
|
||||
$title = ife($attributes['escape'], h($title), $title);
|
||||
if ($attributes['style'] === 'checkbox') {
|
||||
$htmlOptions['value'] = $name;
|
||||
$label = array();
|
||||
|
||||
$tagName = Inflector::camelize($this->model() . '_' . $this->field() . '_'.Inflector::underscore($name));
|
||||
$htmlOptions['id'] = $tagName;
|
||||
$label = array('for' => $tagName);
|
||||
|
||||
if (isset($htmlOptions['checked']) && $htmlOptions['checked'] === true) {
|
||||
$label['class'] = 'selected';
|
||||
}
|
||||
|
||||
list($name) = array_values($this->__name());
|
||||
$select[] = sprintf($this->Html->tags['checkboxmultiple'], $name, $this->Html->_parseAttributes($htmlOptions)) . $this->label(null, $title, $label);
|
||||
|
||||
if(empty($attributes['class'])) {
|
||||
$attributes['class'] = 'checkbox';
|
||||
}
|
||||
|
||||
$select[] = $this->Html->div($attributes['class'], sprintf($this->Html->tags['checkboxmultiple'], $name, $this->Html->_parseAttributes($htmlOptions)) . $this->label(null, $title, $label));
|
||||
} else {
|
||||
$select[] = sprintf($this->Html->tags['selectoption'], $name, $this->Html->_parseAttributes($htmlOptions), $title);
|
||||
}
|
||||
|
|
|
@ -268,7 +268,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->Form->params['_Token']['key'] = 'testKey';
|
||||
|
||||
$result = $this->Form->create('Contact', array('url' => '/contacts/add'));
|
||||
$expected = '/^<form method="post" action="\/contacts\/add"(.+)<input type="hidden" name="data\[__Token\]\[key\]" value="testKey"(.+)<\/p>$/';
|
||||
$expected = '/^<form method="post" action="\/contacts\/add"(.+)<input type="hidden" name="data\[__Token\]\[key\]" value="testKey"(.+)<\/fieldset>$/';
|
||||
$this->assertPattern($expected, $result);
|
||||
|
||||
$result = $this->Form->input('UserForm.published', array('type' => 'text'));
|
||||
|
@ -288,7 +288,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->Form->secure($this->Form->fields);
|
||||
$expected = '/<p style="display: none;"><input type="hidden" name="data\[__Token\]\[fields\]" value="'.$fieldsKey.'" id="(.+)" \/><\/p>$/';
|
||||
$expected = '/<fieldset style="display:none;"><input type="hidden" name="data\[__Token\]\[fields\]" value="'.$fieldsKey.'" id="(.+)" \/><\/fieldset>$/';
|
||||
$this->assertPattern($expected, $result);
|
||||
|
||||
$result = $this->Form->fields;
|
||||
|
@ -306,7 +306,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertFalse($this->UserForm->OpenidUrl->validates());
|
||||
|
||||
$result = $this->Form->create('UserForm', array('type' => 'post', 'action' => 'login'));
|
||||
$this->assertPattern('/^<form\s+[^<>]+><input\s+[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<form\s+[^<>]+><fieldset\s+[^<>]+><input\s+[^<>]+\/><\/fieldset>$/', $result);
|
||||
$this->assertPattern('/^<form[^<>]+id="UserFormLoginForm"[^<>]*>/', $result);
|
||||
$this->assertPattern('/^<form[^<>]+method="post"[^<>]*>/', $result);
|
||||
$this->assertPattern('/^<form[^<>]+action="\/user_forms\/login\/"[^<>]*>/', $result);
|
||||
|
@ -338,7 +338,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertFalse($this->ValidateUser->ValidateProfile->validates());
|
||||
|
||||
$result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add'));
|
||||
$this->assertPattern('/^<form\s+id="[^"]+"\s+method="post"\s+action="\/validate_users\/add\/"[^>]*><input\s+[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<form\s+id="[^"]+"\s+method="post"\s+action="\/validate_users\/add\/"[^>]*><fieldset\s+[^<>]+><input\s+[^<>]+\/><\/fieldset>$/', $result);
|
||||
|
||||
$expected = array(
|
||||
'ValidateUser' => array('email' => 1),
|
||||
|
@ -368,7 +368,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertFalse($this->ValidateUser->ValidateProfile->ValidateItem->validates());
|
||||
|
||||
$result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add'));
|
||||
$this->assertPattern('/^<form\s+id="[^"]+"\s+method="post"\s+action="\/validate_users\/add\/"[^>]*><input\s+[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<form\s+id="[^"]+"\s+method="post"\s+action="\/validate_users\/add\/"[^>]*><fieldset\s+[^<>]+><input\s+[^<>]+\/><\/fieldset>$/', $result);
|
||||
|
||||
$expected = array(
|
||||
'ValidateUser' => array('email' => 1),
|
||||
|
@ -505,7 +505,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
|
||||
function testSelectAsCheckbox() {
|
||||
$result = $this->Form->select('Model.multi_field', array('first', 'second', 'third'), array(0, 1), array('multiple' => 'checkbox'));
|
||||
$this->assertPattern('/^(<input[^<>]+>\s*<label[^<>]*>\w+<\/label>\s*){3}$/', $result);
|
||||
$this->assertPattern('/^(<div[^<>]+>\<input[^<>]+>\s*<label[^<>]*>\w+<\/label><\/div>\s*){3}$/', $result);
|
||||
$this->assertNoPattern('/<label[^<>]*>[^(first|second)]<\/label>/', $result);
|
||||
|
||||
/*$this->assertPattern('/^<input type="checkbox"[^<>]+name="data\[Model\]\[multi_field\]\[\]+value="0"[^<>]+checked="checked">/', $result);
|
||||
|
@ -805,19 +805,19 @@ class FormHelperTest extends CakeTestCase {
|
|||
|
||||
$result = $this->Form->select('Model.multi_field', array('1' => 'first'), null, array('multiple' => 'checkbox'));
|
||||
|
||||
$this->assertPattern('/^<input[^<>]+\/><label[^<>]+>first<\/label>$/', $result);
|
||||
$this->assertPattern('/^<input[^<>]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/><label[^<>]+>first<\/label>$/', $result);
|
||||
$this->assertPattern('/^<input[^<>]+type="checkbox"[^<>]+\/><label[^<>]+>first<\/label>$/', $result);
|
||||
$this->assertPattern('/^<input[^<>]+value="1"[^<>]+\/><label[^<>]+>first<\/label>$/', $result);
|
||||
$this->assertNoPattern('/^<input[^<>]+[^name|type|value]=[^<>\/]*><label[^<>]+>first<\/label>$/', $result);
|
||||
$this->assertPattern('/^<div[^<>]+><input[^<>]+\/><label[^<>]+>first<\/label><\/div>$/', $result);
|
||||
$this->assertPattern('/^<div[^<>]+><input[^<>]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/><label[^<>]+>first<\/label><\/div>$/', $result);
|
||||
$this->assertPattern('/^<div[^<>]+><input[^<>]+type="checkbox"[^<>]+\/><label[^<>]+>first<\/label><\/div>$/', $result);
|
||||
$this->assertPattern('/^<div[^<>]+><input[^<>]+value="1"[^<>]+\/><label[^<>]+>first<\/label><\/div>$/', $result);
|
||||
$this->assertNoPattern('/^<div[^<>]+><input[^<>]+[^name|type|value]=[^<>\/]*><label[^<>]+>first<\/label><\/div>$/', $result);
|
||||
|
||||
$result = $this->Form->select('Model.multi_field', array('2' => 'second'), null, array('multiple' => 'checkbox'));
|
||||
|
||||
$this->assertPattern('/^<input[^<>]+\/><label[^<>]+>second<\/label>$/', $result);
|
||||
$this->assertPattern('/^<input[^<>]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/><label[^<>]+>second<\/label>$/', $result);
|
||||
$this->assertPattern('/^<input[^<>]+type="checkbox"[^<>]+\/><label[^<>]+>second<\/label>$/', $result);
|
||||
$this->assertPattern('/^<input[^<>]+value="2"[^<>]+\/><label[^<>]+>second<\/label>$/', $result);
|
||||
$this->assertNoPattern('/^<input[^<>]+[^name|type|value]=[^<>\/]*><label[^<>]+>second<\/label>$/', $result);
|
||||
$this->assertPattern('/^<div[^<>]+><input[^<>]+\/><label[^<>]+>second<\/label><\/div>$/', $result);
|
||||
$this->assertPattern('/^<div[^<>]+><input[^<>]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/><label[^<>]+>second<\/label><\/div>$/', $result);
|
||||
$this->assertPattern('/^<div[^<>]+><input[^<>]+type="checkbox"[^<>]+\/><label[^<>]+>second<\/label><\/div>$/', $result);
|
||||
$this->assertPattern('/^<div[^<>]+><input[^<>]+value="2"[^<>]+\/><label[^<>]+>second<\/label><\/div>$/', $result);
|
||||
$this->assertNoPattern('/^<div[^<>]+><input[^<>]+[^name|type|value]=[^<>\/]*><label[^<>]+>second<\/label><\/div>$/', $result);
|
||||
}
|
||||
|
||||
function testInputMultipleCheckboxes() {
|
||||
|
@ -861,19 +861,19 @@ class FormHelperTest extends CakeTestCase {
|
|||
|
||||
$result = $this->Form->input('Model.multi_field', array('options' => array('1' => 'first'), 'multiple' => 'checkbox', 'label' => false, 'div' => false));
|
||||
|
||||
$this->assertPattern('/^<input[^<>]+\/><label[^<>]+>first<\/label>$/', $result);
|
||||
$this->assertPattern('/^<input[^<>]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/><label[^<>]+>first<\/label>$/', $result);
|
||||
$this->assertPattern('/^<input[^<>]+type="checkbox"[^<>]+\/><label[^<>]+>first<\/label>$/', $result);
|
||||
$this->assertPattern('/^<input[^<>]+value="1"[^<>]+\/><label[^<>]+>first<\/label>$/', $result);
|
||||
$this->assertNoPattern('/^<input[^<>]+[^name|type|value]=[^<>\/]*><label[^<>]+>first<\/label>$/', $result);
|
||||
$this->assertPattern('/^<div[^<>]+><input[^<>]+\/><label[^<>]+>first<\/label><\/div>$/', $result);
|
||||
$this->assertPattern('/^<div[^<>]+><input[^<>]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/><label[^<>]+>first<\/label><\/div>$/', $result);
|
||||
$this->assertPattern('/^<div[^<>]+><input[^<>]+type="checkbox"[^<>]+\/><label[^<>]+>first<\/label><\/div>$/', $result);
|
||||
$this->assertPattern('/^<div[^<>]+><input[^<>]+value="1"[^<>]+\/><label[^<>]+>first<\/label><\/div>$/', $result);
|
||||
$this->assertNoPattern('/^<div[^<>]+><input[^<>]+[^name|type|value]=[^<>\/]*><label[^<>]+>first<\/label><\/div>$/', $result);
|
||||
|
||||
$result = $this->Form->input('Model.multi_field', array('options' => array('2' => 'second'), 'multiple' => 'checkbox', 'label' => false, 'div' => false));
|
||||
|
||||
$this->assertPattern('/^<input[^<>]+\/><label[^<>]+>second<\/label>$/', $result);
|
||||
$this->assertPattern('/^<input[^<>]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/><label[^<>]+>second<\/label>$/', $result);
|
||||
$this->assertPattern('/^<input[^<>]+type="checkbox"[^<>]+\/><label[^<>]+>second<\/label>$/', $result);
|
||||
$this->assertPattern('/^<input[^<>]+value="2"[^<>]+\/><label[^<>]+>second<\/label>$/', $result);
|
||||
$this->assertNoPattern('/^<input[^<>]+[^name|type|value]=[^<>\/]*><label[^<>]+>second<\/label>$/', $result);
|
||||
$this->assertPattern('/^<div[^<>]+><input[^<>]+\/><label[^<>]+>second<\/label><\/div>$/', $result);
|
||||
$this->assertPattern('/^<div[^<>]+><input[^<>]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/><label[^<>]+>second<\/label><\/div>$/', $result);
|
||||
$this->assertPattern('/^<div[^<>]+><input[^<>]+type="checkbox"[^<>]+\/><label[^<>]+>second<\/label><\/div>$/', $result);
|
||||
$this->assertPattern('/^<div[^<>]+><input[^<>]+value="2"[^<>]+\/><label[^<>]+>second<\/label><\/div>$/', $result);
|
||||
$this->assertNoPattern('/^<div[^<>]+><input[^<>]+[^name|type|value]=[^<>\/]*><label[^<>]+>second<\/label><\/div>$/', $result);
|
||||
}
|
||||
|
||||
function testCheckbox() {
|
||||
|
@ -1241,7 +1241,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
|
||||
function testFormMagicInput() {
|
||||
$result = $this->Form->create('Contact');
|
||||
$this->assertPattern('/^<form\s+id="ContactAddForm"\s+method="post"\s+action="\/contacts\/add\/"\s*><input\s+[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<form\s+id="ContactAddForm"\s+method="post"\s+action="\/contacts\/add\/"\s*><fieldset[^<>]+><input\s+[^<>]+\/><\/fieldset>$/', $result);
|
||||
$this->assertNoPattern('/^<form[^<>]+[^id|method|action]=[^<>]*>/', $result);
|
||||
|
||||
$result = $this->Form->input('name');
|
||||
|
@ -1294,7 +1294,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
|
||||
function testForMagicInputNonExistingNorValidated() {
|
||||
$result = $this->Form->create('Contact');
|
||||
$this->assertPattern('/^<form\s+id="ContactAddForm"\s+method="post"\s+action="\/contacts\/add\/"\s*><input\s+[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<form\s+id="ContactAddForm"\s+method="post"\s+action="\/contacts\/add\/"\s*><fieldset[^<>]+><input\s+[^<>]+\/><\/fieldset>$/', $result);
|
||||
$this->assertNoPattern('/^<form[^<>]+[^id|method|action]=[^<>]*>/', $result);
|
||||
|
||||
$result = $this->Form->input('Contact.non_existing_nor_validated', array('div' => false));
|
||||
|
@ -1328,7 +1328,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
|
||||
function testFormMagicInputLabel() {
|
||||
$result = $this->Form->create('Contact');
|
||||
$this->assertPattern('/^<form\s+id="ContactAddForm"\s+method="post"\s+action="\/contacts\/add\/"\s*><input\s+[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<form\s+id="ContactAddForm"\s+method="post"\s+action="\/contacts\/add\/"\s*><fieldset[^<>]+><input\s+[^<>]+\/><\/fieldset>$/', $result);
|
||||
|
||||
$result = $this->Form->input('Contact.name', array('div' => false, 'label' => false));
|
||||
$this->assertPattern('/^<input name="data\[Contact\]\[name\]" type="text" maxlength="255" value="" id="ContactName" \/>$/', $result);
|
||||
|
|
Loading…
Reference in a new issue