mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Adding hidden form inputs for REST routing
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5913 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
fbd3811cd1
commit
7e9b05e429
5 changed files with 38 additions and 19 deletions
|
@ -349,6 +349,14 @@ class Dispatcher extends Object {
|
||||||
} else {
|
} else {
|
||||||
$params['form'] = $_POST;
|
$params['form'] = $_POST;
|
||||||
}
|
}
|
||||||
|
if (isset($params['form']['_method'])) {
|
||||||
|
if (isset($_SERVER) && !empty($_SERVER)) {
|
||||||
|
$_SERVER['REQUEST_METHOD'] = $params['form']['_method'];
|
||||||
|
} else {
|
||||||
|
$_ENV['REQUEST_METHOD'] = $params['form']['_method'];
|
||||||
|
}
|
||||||
|
unset($params['form']['_method']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($params['form']['data'])) {
|
if (isset($params['form']['data'])) {
|
||||||
|
|
|
@ -392,8 +392,11 @@ class Helper extends Overloadable {
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function domId($options = null, $id = 'id') {
|
function domId($options = null, $id = 'id') {
|
||||||
if (is_array($options) && !isset($options[$id])) {
|
if (is_array($options) && !array_key_exists($id, $options)) {
|
||||||
$options[$id] = $this->model() . Inflector::camelize($this->field());
|
$options[$id] = $this->model() . Inflector::camelize($this->field());
|
||||||
|
} elseif (is_array($options) && $options[$id] === null) {
|
||||||
|
unset($options[$id]);
|
||||||
|
return $options;
|
||||||
} elseif (!is_array($options)) {
|
} elseif (!is_array($options)) {
|
||||||
$this->setFormTag($options);
|
$this->setFormTag($options);
|
||||||
return $this->model() . Inflector::camelize($this->field());
|
return $this->model() . Inflector::camelize($this->field());
|
||||||
|
@ -419,7 +422,7 @@ class Helper extends Overloadable {
|
||||||
$this->setFormTag($field);
|
$this->setFormTag($field);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($options) && isset($options[$key])) {
|
if (is_array($options) && array_key_exists($key, $options)) {
|
||||||
return $options;
|
return $options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -552,7 +552,7 @@ class AjaxHelper extends AppHelper {
|
||||||
* @return string JavaScript block to create a droppable element
|
* @return string JavaScript block to create a droppable element
|
||||||
*/
|
*/
|
||||||
function dropRemote($id, $options = array(), $ajaxOptions = array()) {
|
function dropRemote($id, $options = array(), $ajaxOptions = array()) {
|
||||||
$options['onDrop'] = "function(element, droppable) {" . $this->remoteFunction($ajaxOptions) . "}";
|
$options['onDrop'] = "function(element, droppable, event) {" . $this->remoteFunction($ajaxOptions) . "}";
|
||||||
$options = $this->_optionsToString($options, array('accept', 'overlap', 'hoverclass'));
|
$options = $this->_optionsToString($options, array('accept', 'overlap', 'hoverclass'));
|
||||||
$options = $this->_buildOptions($options, $this->dropOptions);
|
$options = $this->_buildOptions($options, $this->dropOptions);
|
||||||
return $this->Javascript->codeBlock("Droppables.add('{$id}', {$options});");
|
return $this->Javascript->codeBlock("Droppables.add('{$id}', {$options});");
|
||||||
|
|
|
@ -184,7 +184,7 @@ class FormHelper extends AppHelper {
|
||||||
case 'post':
|
case 'post':
|
||||||
case 'put':
|
case 'put':
|
||||||
case 'delete':
|
case 'delete':
|
||||||
//$append .= $this->hidden('_method', array('name' => '_method', 'value' => up($options['type']), 'id' => $options['id'] . 'Method'));
|
$append .= $this->hidden('_method', array('name' => '_method', 'value' => up($options['type']), 'id' => null));
|
||||||
default:
|
default:
|
||||||
$htmlAttributes['method'] = 'post';
|
$htmlAttributes['method'] = 'post';
|
||||||
break;
|
break;
|
||||||
|
@ -709,12 +709,7 @@ class FormHelper extends AppHelper {
|
||||||
$output = null;
|
$output = null;
|
||||||
if (isset($object) && isset($options['value']) && ($options['value'] == 0 || $options['value'] == 1)) {
|
if (isset($object) && isset($options['value']) && ($options['value'] == 0 || $options['value'] == 1)) {
|
||||||
$db =& ConnectionManager::getDataSource($object->useDbConfig);
|
$db =& ConnectionManager::getDataSource($object->useDbConfig);
|
||||||
if (is_object($db)) {
|
$value = $db->boolean($options['value'], false);
|
||||||
$value = $db->boolean($options['value'], false);
|
|
||||||
} else {
|
|
||||||
pr(get_class($object));
|
|
||||||
pr($object->useDbConfig);
|
|
||||||
}
|
|
||||||
$options['value'] = 1;
|
$options['value'] = 1;
|
||||||
}
|
}
|
||||||
$output = $this->hidden($fieldName, array('value' => '0', 'id' => $options['id'] . '_'), true);
|
$output = $this->hidden($fieldName, array('value' => '0', 'id' => $options['id'] . '_'), true);
|
||||||
|
@ -856,11 +851,10 @@ class FormHelper extends AppHelper {
|
||||||
if (!empty($options['value']) || $options['value'] === '0') {
|
if (!empty($options['value']) || $options['value'] === '0') {
|
||||||
$value = $options['value'];
|
$value = $options['value'];
|
||||||
}
|
}
|
||||||
$this->__secure($key, $value);
|
|
||||||
|
|
||||||
/*if (in_array($fieldName, array('_method', '_fields'))) {
|
if (!in_array($fieldName, array('_method'))) {
|
||||||
$model = null;
|
$this->__secure($key, $value);
|
||||||
}*/
|
}
|
||||||
return $this->output(sprintf($this->Html->tags['hidden'], $options['name'], $this->_parseAttributes($options, array('name', 'class'), '', ' ')));
|
return $this->output(sprintf($this->Html->tags['hidden'], $options['name'], $this->_parseAttributes($options, array('name', 'class'), '', ' ')));
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -44,6 +44,7 @@ class ContactTestController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
class Contact extends CakeTestModel {
|
class Contact extends CakeTestModel {
|
||||||
|
|
||||||
var $primaryKey = 'id';
|
var $primaryKey = 'id';
|
||||||
var $useTable = false;
|
var $useTable = false;
|
||||||
var $name = 'Contact';
|
var $name = 'Contact';
|
||||||
|
@ -60,6 +61,7 @@ class Contact extends CakeTestModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
class UserForm extends CakeTestModel {
|
class UserForm extends CakeTestModel {
|
||||||
|
|
||||||
var $useTable = false;
|
var $useTable = false;
|
||||||
var $primaryKey = 'id';
|
var $primaryKey = 'id';
|
||||||
var $name = 'UserForm';
|
var $name = 'UserForm';
|
||||||
|
@ -97,6 +99,7 @@ class OpenidUrl extends CakeTestModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
class ValidateUser extends CakeTestModel {
|
class ValidateUser extends CakeTestModel {
|
||||||
|
|
||||||
var $primaryKey = 'id';
|
var $primaryKey = 'id';
|
||||||
var $useTable = false;
|
var $useTable = false;
|
||||||
var $name = 'ValidateUser';
|
var $name = 'ValidateUser';
|
||||||
|
@ -119,6 +122,7 @@ class ValidateUser extends CakeTestModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
class ValidateProfile extends CakeTestModel {
|
class ValidateProfile extends CakeTestModel {
|
||||||
|
|
||||||
var $primaryKey = 'id';
|
var $primaryKey = 'id';
|
||||||
var $useTable = false;
|
var $useTable = false;
|
||||||
var $name = 'ValidateProfile';
|
var $name = 'ValidateProfile';
|
||||||
|
@ -144,6 +148,7 @@ class ValidateProfile extends CakeTestModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
class ValidateItem extends CakeTestModel {
|
class ValidateItem extends CakeTestModel {
|
||||||
|
|
||||||
var $primaryKey = 'id';
|
var $primaryKey = 'id';
|
||||||
var $useTable = false;
|
var $useTable = false;
|
||||||
var $name = 'ValidateItem';
|
var $name = 'ValidateItem';
|
||||||
|
@ -303,7 +308,16 @@ class FormHelperTest extends CakeTestCase {
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
|
|
||||||
$result = $this->Form->create('UserForm', array('type' => 'post', 'action' => 'login'));
|
$result = $this->Form->create('UserForm', array('type' => 'post', 'action' => 'login'));
|
||||||
$this->assertPattern('/^<form\s+id="[^"]+"\s+method="post"\s+action="\/user_forms\/login\/"[^>]*>$/', $result);
|
$this->assertPattern('/^<form\s+[^<>]+><input\s+[^<>]+\/>$/', $result);
|
||||||
|
$this->assertPattern('/^<form[^<>]+id="UserFormLoginForm"[^<>]*>/', $result);
|
||||||
|
$this->assertPattern('/^<form[^<>]+method="post"[^<>]*>/', $result);
|
||||||
|
$this->assertPattern('/^<form[^<>]+action="\/user_forms\/login\/"[^<>]*>/', $result);
|
||||||
|
$this->assertNoPattern('/<form[^<>]+[^id|method|action]=[^<>\/]*>/', $result);
|
||||||
|
|
||||||
|
$this->assertPattern('/<input[^<>]+type="hidden"[^<>]*\/>/', $result);
|
||||||
|
$this->assertPattern('/<input[^<>]+name="_method"[^<>]*\/>/', $result);
|
||||||
|
$this->assertPattern('/<input[^<>]+value="POST"[^<>]*\/>/', $result);
|
||||||
|
$this->assertNoPattern('/<input[^<>]+[^type|name|value]=[^<>\/]*\/>/', $result);
|
||||||
|
|
||||||
$expected = array('OpenidUrl' => array('openid_not_registered' => 1));
|
$expected = array('OpenidUrl' => array('openid_not_registered' => 1));
|
||||||
$this->assertEqual($this->Form->validationErrors, $expected);
|
$this->assertEqual($this->Form->validationErrors, $expected);
|
||||||
|
@ -326,7 +340,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
$this->assertFalse($this->ValidateUser->ValidateProfile->validates());
|
$this->assertFalse($this->ValidateUser->ValidateProfile->validates());
|
||||||
|
|
||||||
$result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add'));
|
$result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add'));
|
||||||
$this->assertPattern('/^<form\s+id="[^"]+"\s+method="post"\s+action="\/validate_users\/add\/"[^>]*>$/', $result);
|
$this->assertPattern('/^<form\s+id="[^"]+"\s+method="post"\s+action="\/validate_users\/add\/"[^>]*><input\s+[^<>]+\/>$/', $result);
|
||||||
|
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'ValidateUser' => array('email' => 1),
|
'ValidateUser' => array('email' => 1),
|
||||||
|
@ -356,7 +370,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
$this->assertFalse($this->ValidateUser->ValidateProfile->ValidateItem->validates());
|
$this->assertFalse($this->ValidateUser->ValidateProfile->ValidateItem->validates());
|
||||||
|
|
||||||
$result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add'));
|
$result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add'));
|
||||||
$this->assertPattern('/^<form\s+id="[^"]+"\s+method="post"\s+action="\/validate_users\/add\/"[^>]*>$/', $result);
|
$this->assertPattern('/^<form\s+id="[^"]+"\s+method="post"\s+action="\/validate_users\/add\/"[^>]*><input\s+[^<>]+\/>$/', $result);
|
||||||
|
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'ValidateUser' => array('email' => 1),
|
'ValidateUser' => array('email' => 1),
|
||||||
|
@ -1079,7 +1093,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
|
|
||||||
function testFormMagicInput() {
|
function testFormMagicInput() {
|
||||||
$result = $this->Form->create('Contact');
|
$result = $this->Form->create('Contact');
|
||||||
$this->assertPattern('/^<form\s+id="ContactAddForm"\s+method="post"\s+action="\/contacts\/add\/"\s*>$/', $result);
|
$this->assertPattern('/^<form\s+id="ContactAddForm"\s+method="post"\s+action="\/contacts\/add\/"\s*><input\s+[^<>]+\/>$/', $result);
|
||||||
$this->assertNoPattern('/^<form[^<>]+[^id|method|action]=[^<>]*>/', $result);
|
$this->assertNoPattern('/^<form[^<>]+[^id|method|action]=[^<>]*>/', $result);
|
||||||
|
|
||||||
$result = $this->Form->input('name');
|
$result = $this->Form->input('name');
|
||||||
|
@ -1133,7 +1147,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
|
|
||||||
function testFormMagicInputLabel() {
|
function testFormMagicInputLabel() {
|
||||||
$result = $this->Form->create('Contact');
|
$result = $this->Form->create('Contact');
|
||||||
$this->assertPattern('/^<form\s+id="ContactAddForm"\s+method="post"\s+action="\/contacts\/add\/"\s*>$/', $result);
|
$this->assertPattern('/^<form\s+id="ContactAddForm"\s+method="post"\s+action="\/contacts\/add\/"\s*><input\s+[^<>]+\/>$/', $result);
|
||||||
|
|
||||||
$result = $this->Form->input('Contact.name', array('div' => false, 'label' => false));
|
$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);
|
$this->assertPattern('/^<input name="data\[Contact\]\[name\]" type="text" maxlength="255" value="" id="ContactName" \/>$/', $result);
|
||||||
|
|
Loading…
Add table
Reference in a new issue