Skip to content
Permalink
Browse files

Updated FormHelper::end() to use new string template.

The method no longer generates submit button too.
  • Loading branch information...
ADmad committed Feb 18, 2014
1 parent 999429c commit 5662eaaa3bb1a11c9f0f888deeecd43ad171951c
Showing with 5 additions and 107 deletions.
  1. +5 −32 src/View/Helper/FormHelper.php
  2. +0 −75 tests/TestCase/View/Helper/FormHelperTest.php
@@ -444,48 +444,21 @@ protected function _csrfField() {
* Closes an HTML form, cleans up values set by FormHelper::create(), and writes hidden
* input fields where appropriate.
*
* If $options is set a form submit button will be created. Options can be either a string or an array.
*
* {{{
* array usage:
*
* array('label' => 'save'); value="save"
* array('label' => 'save', 'name' => 'Whatever'); value="save" name="Whatever"
* array('name' => 'Whatever'); value="Submit" name="Whatever"
* array('label' => 'save', 'name' => 'Whatever', 'div' => 'good') <div class="good"> value="save" name="Whatever"
* array('label' => 'save', 'name' => 'Whatever', 'div' => array('class' => 'good')); <div class="good"> value="save" name="Whatever"
* }}}
*
* @param string|array $options as a string will use $options as the value of button,
* @return string a closing FORM tag optional submit button.
* @return string A closing FORM tag.
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#closing-the-form
*/
public function end($options = null) {
$out = null;
$submit = null;
public function end() {
$out = '';
if ($options !== null) {
$submitOptions = array();
if (is_string($options)) {
$submit = $options;
} else {
if (isset($options['label'])) {
$submit = $options['label'];
unset($options['label']);
}
$submitOptions = $options;
}
$out .= $this->submit($submit, $submitOptions);
}
if (
$this->requestType !== 'get' &&
isset($this->request['_Token']) &&
!empty($this->request['_Token'])
) {
$out .= $this->secure($this->fields);
$this->fields = array();
}
$out .= $this->Html->useTag('formend');
$out .= $this->formatTemplate('formend', []);
$this->requestType = null;
$this->_context = null;
@@ -8323,82 +8323,7 @@ public function testFormMagicInputLabel() {
* @return void
*/
public function testFormEnd() {
$this->markTestIncomplete('Need to revisit once models work again.');
$this->assertEquals('</form>', $this->Form->end());
$result = $this->Form->end('');
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'submit', 'value' => ''),
'/div',
'/form'
);
$this->assertTags($result, $expected);
$result = $this->Form->end(array('label' => ''));
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'submit', 'value' => ''),
'/div',
'/form'
);
$this->assertTags($result, $expected);
$result = $this->Form->end('save');
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'submit', 'value' => 'save'),
'/div',
'/form'
);
$this->assertTags($result, $expected);
$result = $this->Form->end(array('label' => 'save'));
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'submit', 'value' => 'save'),
'/div',
'/form'
);
$this->assertTags($result, $expected);
$result = $this->Form->end(array('label' => 'save', 'name' => 'Whatever'));
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'submit', 'value' => 'save', 'name' => 'Whatever'),
'/div',
'/form'
);
$this->assertTags($result, $expected);
$result = $this->Form->end(array('name' => 'Whatever'));
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'submit', 'value' => 'Submit', 'name' => 'Whatever'),
'/div',
'/form'
);
$this->assertTags($result, $expected);
$result = $this->Form->end(array('label' => 'save', 'name' => 'Whatever', 'div' => 'good'));
$expected = array(
'div' => array('class' => 'good'),
'input' => array('type' => 'submit', 'value' => 'save', 'name' => 'Whatever'),
'/div',
'/form'
);
$this->assertTags($result, $expected);
$result = $this->Form->end(array(
'label' => 'save', 'name' => 'Whatever', 'div' => array('class' => 'good')
));
$expected = array(
'div' => array('class' => 'good'),
'input' => array('type' => 'submit', 'value' => 'save', 'name' => 'Whatever'),
'/div',
'/form'
);
$this->assertTags($result, $expected);
}
/**

0 comments on commit 5662eaa

Please sign in to comment.
You can’t perform that action at this time.