mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-18 23:49:55 +00:00
Merge branch '1.3-formhelper' into 1.3-misc
This commit is contained in:
commit
aa0c7cbd7f
6 changed files with 87 additions and 52 deletions
85
cake/libs/view/helpers/form.php
Normal file → Executable file
85
cake/libs/view/helpers/form.php
Normal file → Executable file
|
@ -1,6 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
/* SVN FILE: $Id$ */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Automatic generation of HTML FORMs from given data.
|
* Automatic generation of HTML FORMs from given data.
|
||||||
*
|
*
|
||||||
|
@ -9,20 +7,16 @@
|
||||||
* PHP versions 4 and 5
|
* PHP versions 4 and 5
|
||||||
*
|
*
|
||||||
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
|
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
|
||||||
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
||||||
*
|
*
|
||||||
* Licensed under The MIT License
|
* Licensed under The MIT License
|
||||||
* Redistributions of files must retain the above copyright notice.
|
* Redistributions of files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @filesource
|
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
||||||
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
|
||||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
||||||
* @package cake
|
* @package cake
|
||||||
* @subpackage cake.cake.libs.view.helpers
|
* @subpackage cake.cake.libs.view.helpers
|
||||||
* @since CakePHP(tm) v 0.10.0.1076
|
* @since CakePHP(tm) v 0.10.0.1076
|
||||||
* @version $Revision$
|
|
||||||
* @modifiedby $LastChangedBy$
|
|
||||||
* @lastmodified $Date$
|
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -78,16 +72,27 @@ class FormHelper extends AppHelper {
|
||||||
*/
|
*/
|
||||||
var $requestType = null;
|
var $requestType = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Persistent default options used by input(). Set by FormHelper::create().
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @access protected
|
||||||
|
*/
|
||||||
|
var $_inputDefaults = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an HTML FORM element.
|
* Returns an HTML FORM element.
|
||||||
*
|
*
|
||||||
* Options:
|
* #### Options:
|
||||||
*
|
*
|
||||||
* - 'type' Form method defaults to POST
|
* - 'type' Form method defaults to POST
|
||||||
* - 'action' The Action the form submits to. Can be a string or array,
|
* - 'action' The Action the form submits to. Can be a string or array,
|
||||||
* - 'url' The url the form submits to. Can be a string or a url array,
|
* - 'url' The url the form submits to. Can be a string or a url array,
|
||||||
* - 'default' Allows for the creation of Ajax forms.
|
* - 'default' Allows for the creation of Ajax forms.
|
||||||
* - 'onsubmit' Used in conjunction with 'default' to create ajax forms.
|
* - 'onsubmit' Used in conjunction with 'default' to create ajax forms.
|
||||||
|
* - 'inputDefaults' set the default $options for FormHelper::input(). Any options that would
|
||||||
|
* be set when using FormHelper::input() can be set here. Options set with `inputDefaults`
|
||||||
|
* can be overridden when calling input()
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $model The model object which the form is being defined for
|
* @param string $model The model object which the form is being defined for
|
||||||
|
@ -179,8 +184,11 @@ class FormHelper extends AppHelper {
|
||||||
'type' => ($created && empty($options['action'])) ? 'put' : 'post',
|
'type' => ($created && empty($options['action'])) ? 'put' : 'post',
|
||||||
'action' => null,
|
'action' => null,
|
||||||
'url' => null,
|
'url' => null,
|
||||||
'default' => true),
|
'default' => true,
|
||||||
|
'inputDefaults' => array()),
|
||||||
$options);
|
$options);
|
||||||
|
$this->_inputDefaults = $options['inputDefaults'];
|
||||||
|
unset($options['inputDefaults']);
|
||||||
|
|
||||||
if (empty($options['url']) || is_array($options['url'])) {
|
if (empty($options['url']) || is_array($options['url'])) {
|
||||||
if (empty($options['url']['controller'])) {
|
if (empty($options['url']['controller'])) {
|
||||||
|
@ -607,8 +615,11 @@ class FormHelper extends AppHelper {
|
||||||
$this->setEntity($fieldName);
|
$this->setEntity($fieldName);
|
||||||
$entity = join('.', $view->entity());
|
$entity = join('.', $view->entity());
|
||||||
|
|
||||||
$defaults = array('before' => null, 'between' => null, 'after' => null);
|
$options = array_merge(
|
||||||
$options = array_merge($defaults, $options);
|
array('before' => null, 'between' => null, 'after' => null),
|
||||||
|
$this->_inputDefaults,
|
||||||
|
$options
|
||||||
|
);
|
||||||
|
|
||||||
if (!isset($options['type'])) {
|
if (!isset($options['type'])) {
|
||||||
$options['type'] = 'text';
|
$options['type'] = 'text';
|
||||||
|
@ -784,10 +795,10 @@ class FormHelper extends AppHelper {
|
||||||
unset($options['dateFormat']);
|
unset($options['dateFormat']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$type = $options['type'];
|
$type = $options['type'];
|
||||||
$before = $options['before'];
|
$before = $options['before'];
|
||||||
$between = $options['between'];
|
$between = $options['between'];
|
||||||
$after = $options['after'];
|
$after = $options['after'];
|
||||||
unset($options['type'], $options['before'], $options['between'], $options['after']);
|
unset($options['type'], $options['before'], $options['between'], $options['after']);
|
||||||
|
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
|
@ -1536,8 +1547,8 @@ class FormHelper extends AppHelper {
|
||||||
* - 'separator' The contents of the string between select elements. Defaults to '-'
|
* - 'separator' The contents of the string between select elements. Defaults to '-'
|
||||||
*
|
*
|
||||||
* @param string $fieldName Prefix name for the SELECT element
|
* @param string $fieldName Prefix name for the SELECT element
|
||||||
* @param string $dateFormat DMY, MDY, YMD or NONE.
|
* @param string $dateFormat DMY, MDY, YMD.
|
||||||
* @param string $timeFormat 12, 24, NONE
|
* @param string $timeFormat 12, 24.
|
||||||
* @param string $selected Option which is selected.
|
* @param string $selected Option which is selected.
|
||||||
* @param string $attributes array of Attributes
|
* @param string $attributes array of Attributes
|
||||||
* @param bool $showEmpty Whether or not to show an empty default value.
|
* @param bool $showEmpty Whether or not to show an empty default value.
|
||||||
|
@ -1573,7 +1584,7 @@ class FormHelper extends AppHelper {
|
||||||
$days[1] = $selected;
|
$days[1] = $selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($timeFormat != 'NONE' && !empty($timeFormat)) {
|
if (!empty($timeFormat)) {
|
||||||
$time = explode(':', $days[1]);
|
$time = explode(':', $days[1]);
|
||||||
$check = str_replace(':', '', $days[1]);
|
$check = str_replace(':', '', $days[1]);
|
||||||
|
|
||||||
|
@ -1635,28 +1646,25 @@ class FormHelper extends AppHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$opt = '';
|
$selects = array();
|
||||||
|
foreach (preg_split('//', $dateFormat, -1, PREG_SPLIT_NO_EMPTY) as $char) {
|
||||||
if ($dateFormat != 'NONE') {
|
switch ($char) {
|
||||||
$selects = array();
|
case 'Y':
|
||||||
foreach (preg_split('//', $dateFormat, -1, PREG_SPLIT_NO_EMPTY) as $char) {
|
$selects[] = $this->year(
|
||||||
switch ($char) {
|
$fieldName, $minYear, $maxYear, $year, $selectYearAttr, $showEmpty
|
||||||
case 'Y':
|
);
|
||||||
$selects[] = $this->year(
|
break;
|
||||||
$fieldName, $minYear, $maxYear, $year, $selectYearAttr, $showEmpty
|
case 'M':
|
||||||
);
|
$selectMonthAttr['monthNames'] = $monthNames;
|
||||||
break;
|
$selects[] = $this->month($fieldName, $month, $selectMonthAttr, $showEmpty);
|
||||||
case 'M':
|
break;
|
||||||
$selectMonthAttr['monthNames'] = $monthNames;
|
case 'D':
|
||||||
$selects[] = $this->month($fieldName, $month, $selectMonthAttr, $showEmpty);
|
$selects[] = $this->day($fieldName, $day, $selectDayAttr, $showEmpty);
|
||||||
break;
|
break;
|
||||||
case 'D':
|
|
||||||
$selects[] = $this->day($fieldName, $day, $selectDayAttr, $showEmpty);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$opt = implode($separator, $selects);
|
|
||||||
}
|
}
|
||||||
|
$opt = implode($separator, $selects);
|
||||||
|
|
||||||
if (!empty($interval) && $interval > 1 && !empty($min)) {
|
if (!empty($interval) && $interval > 1 && !empty($min)) {
|
||||||
$min = round($min * (1 / $interval)) * $interval;
|
$min = round($min * (1 / $interval)) * $interval;
|
||||||
}
|
}
|
||||||
|
@ -1671,7 +1679,6 @@ class FormHelper extends AppHelper {
|
||||||
$this->minute($fieldName, $min, $selectMinuteAttr, $showEmpty) . ' ' .
|
$this->minute($fieldName, $min, $selectMinuteAttr, $showEmpty) . ' ' .
|
||||||
$this->meridian($fieldName, $meridian, $selectMeridianAttr, $showEmpty);
|
$this->meridian($fieldName, $meridian, $selectMeridianAttr, $showEmpty);
|
||||||
break;
|
break;
|
||||||
case 'NONE':
|
|
||||||
default:
|
default:
|
||||||
$opt .= '';
|
$opt .= '';
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -37,7 +37,7 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
|
||||||
**/
|
**/
|
||||||
var $_optionMap = array(
|
var $_optionMap = array(
|
||||||
'request' => array(
|
'request' => array(
|
||||||
'async' => 'asyncrhronous',
|
'async' => 'asynchronous',
|
||||||
'data' => 'parameters',
|
'data' => 'parameters',
|
||||||
'before' => 'onCreate',
|
'before' => 'onCreate',
|
||||||
'success' => 'onSuccess',
|
'success' => 'onSuccess',
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
/* SVN FILE: $Id: model.test.php 8225 2009-07-08 03:25:30Z mark_story $ */
|
/* SVN FILE: $Id: model.test.php 8225 2009-07-08 03:25:30Z mark_story $ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ModelDeleteTest file
|
* ModelIntegrationTest file
|
||||||
*
|
*
|
||||||
* Long description for file
|
* Long description for file
|
||||||
*
|
*
|
||||||
|
@ -26,7 +26,6 @@
|
||||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||||
*/
|
*/
|
||||||
require_once dirname(__FILE__) . DS . 'model.test.php';
|
require_once dirname(__FILE__) . DS . 'model.test.php';
|
||||||
require_once dirname(__FILE__) . DS . 'model_integration.test.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ModelIntegrationTest
|
* ModelIntegrationTest
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||||
*/
|
*/
|
||||||
require_once dirname(__FILE__) . DS . 'model.test.php';
|
require_once dirname(__FILE__) . DS . 'model.test.php';
|
||||||
require_once dirname(__FILE__) . DS . 'model_validation.test.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ModelValidationTest
|
* ModelValidationTest
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
/* SVN FILE: $Id$ */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FormHelperTest file
|
* FormHelperTest file
|
||||||
*
|
*
|
||||||
|
@ -9,20 +7,16 @@
|
||||||
* PHP versions 4 and 5
|
* PHP versions 4 and 5
|
||||||
*
|
*
|
||||||
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
||||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
* Copyright 2006-2009, Cake Software Foundation, Inc.
|
||||||
*
|
*
|
||||||
* Licensed under The Open Group Test Suite License
|
* Licensed under The Open Group Test Suite License
|
||||||
* Redistributions of files must retain the above copyright notice.
|
* Redistributions of files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @filesource
|
* @copyright Copyright 2006-2009, Cake Software Foundation, Inc.
|
||||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
|
||||||
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
||||||
* @package cake
|
* @package cake
|
||||||
* @subpackage cake.tests.cases.libs.view.helpers
|
* @subpackage cake.tests.cases.libs.view.helpers
|
||||||
* @since CakePHP(tm) v 1.2.0.4206
|
* @since CakePHP(tm) v 1.2.0.4206
|
||||||
* @version $Revision$
|
|
||||||
* @modifiedby $LastChangedBy$
|
|
||||||
* @lastmodified $Date$
|
|
||||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||||
*/
|
*/
|
||||||
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
|
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
|
||||||
|
@ -4717,6 +4711,31 @@ class FormHelperTest extends CakeTestCase {
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test that inputDefaults are stored and used.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
**/
|
||||||
|
function testCreateWithInputDefaults() {
|
||||||
|
$this->Form->create('User', array(
|
||||||
|
'inputDefaults' => array('div' => false, 'label' => false)
|
||||||
|
));
|
||||||
|
$result = $this->Form->input('username');
|
||||||
|
$expected = array(
|
||||||
|
'input' => array('type' => 'text', 'name' => 'data[User][username]', 'id' => 'UserUsername', 'value' => '')
|
||||||
|
);
|
||||||
|
$this->assertTags($result, $expected);
|
||||||
|
|
||||||
|
$result = $this->Form->input('username', array('div' => true, 'label' => 'username'));
|
||||||
|
$expected = array(
|
||||||
|
'div' => array('class' => 'input text'),
|
||||||
|
'label' => array('for' => 'UserUsername'), 'username', '/label',
|
||||||
|
'input' => array('type' => 'text', 'name' => 'data[User][username]', 'id' => 'UserUsername', 'value' => ''),
|
||||||
|
'/div'
|
||||||
|
);
|
||||||
|
$this->assertTags($result, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test base form url when url param is passed with multiple parameters (&)
|
* Test base form url when url param is passed with multiple parameters (&)
|
||||||
*
|
*
|
||||||
|
|
|
@ -227,7 +227,7 @@ class PrototypeEngineHelperTestCase extends CakeTestCase {
|
||||||
));
|
));
|
||||||
$expected = 'var jsRequest = new Ajax.Request("/people/edit/1", {method:"post", onComplete:doSuccess, onFailure:handleError, parameters:$("element").serialize()});';
|
$expected = 'var jsRequest = new Ajax.Request("/people/edit/1", {method:"post", onComplete:doSuccess, onFailure:handleError, parameters:$("element").serialize()});';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->Proto->request('/people/edit/1', array(
|
$result = $this->Proto->request('/people/edit/1', array(
|
||||||
'method' => 'post',
|
'method' => 'post',
|
||||||
'before' => 'doBefore();',
|
'before' => 'doBefore();',
|
||||||
|
@ -237,6 +237,17 @@ class PrototypeEngineHelperTestCase extends CakeTestCase {
|
||||||
));
|
));
|
||||||
$expected = 'var jsRequest = new Ajax.Request("/people/edit/1", {method:"post", onComplete:function (transport) {doComplete();}, onCreate:function (transport) {doBefore();}, onFailure:function (response, jsonHeader) {handleError();}, onSuccess:function (response, jsonHeader) {doSuccess();}});';
|
$expected = 'var jsRequest = new Ajax.Request("/people/edit/1", {method:"post", onComplete:function (transport) {doComplete();}, onCreate:function (transport) {doBefore();}, onFailure:function (response, jsonHeader) {handleError();}, onSuccess:function (response, jsonHeader) {doSuccess();}});';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$result = $this->Proto->request('/people/edit/1', array(
|
||||||
|
'async' => false,
|
||||||
|
'method' => 'post',
|
||||||
|
'before' => 'doBefore();',
|
||||||
|
'success' => 'doSuccess();',
|
||||||
|
'complete' => 'doComplete();',
|
||||||
|
'error' => 'handleError();',
|
||||||
|
));
|
||||||
|
$expected = 'var jsRequest = new Ajax.Request("/people/edit/1", {asynchronous:false, method:"post", onComplete:function (transport) {doComplete();}, onCreate:function (transport) {doBefore();}, onFailure:function (response, jsonHeader) {handleError();}, onSuccess:function (response, jsonHeader) {doSuccess();}});';
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue