From b7e554fcd7778457e9c38e2cce517a60e8fea197 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sat, 25 Jun 2011 01:40:50 -0400 Subject: [PATCH] Starting to update FormHelper's internals to work with changes in Helper. --- lib/Cake/View/Helper/FormHelper.php | 31 +++++++++++++++-------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index a4b8c4f25ec..22ad47da1c2 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -229,12 +229,11 @@ public function create($model = null, $options = array()) { if ($model !== false) { $object = $this->_introspectModel($model); - $this->setEntity($model . '.', true); } + $this->setEntity($model, true); - $modelEntity = $this->model(); - if ($model !== false && isset($this->fieldset[$modelEntity]['key'])) { - $data = $this->fieldset[$modelEntity]; + if ($model !== false && isset($this->fieldset[$model]['key'])) { + $data = $this->fieldset[$model]; $recordExists = ( isset($this->request->data[$model]) && !empty($this->request->data[$model][$data['key']]) && @@ -306,7 +305,8 @@ public function create($model = null, $options = array()) { case 'put': case 'delete': $append .= $this->hidden('_method', array( - 'name' => '_method', 'value' => strtoupper($options['type']), 'id' => null + 'name' => '_method', 'value' => strtoupper($options['type']), 'id' => null, + 'secure' => self::SECURE_SKIP )); default: $htmlAttributes['method'] = 'post'; @@ -337,8 +337,9 @@ public function create($model = null, $options = array()) { $this->fields = array(); if (!empty($this->request->params['_Token'])) { $append .= $this->hidden('_Token.key', array( - 'value' => $this->request->params['_Token']['key'], 'id' => 'Token' . mt_rand()) - ); + 'value' => $this->request->params['_Token']['key'], 'id' => 'Token' . mt_rand(), + 'secure' => self::SECURE_SKIP + )); if (!empty($this->request['_Token']['unlockedFields'])) { foreach ((array)$this->request['_Token']['unlockedFields'] as $unlocked) { @@ -351,7 +352,6 @@ public function create($model = null, $options = array()) { $append = $this->Html->useTag('block', ' style="display:none;"', $append); } - $this->setEntity($model . '.', true); return $this->Html->useTag('form', $action, $htmlAttributes) . $append; } @@ -1297,9 +1297,8 @@ public function hidden($fieldName, $options = array()) { $options = $this->_initInputField($fieldName, array_merge( $options, array('secure' => self::SECURE_SKIP) )); - $model = $this->model(); - if ($fieldName !== '_method' && $model !== '_Token' && $secure) { + if ($secure && $secure !== self::SECURE_SKIP) { $this->__secure(true, null, '' . $options['value']); } @@ -2349,18 +2348,20 @@ protected function _initInputField($field, $options = array()) { $secure = (isset($this->request['_Token']) && !empty($this->request['_Token'])); } + $result = parent::_initInputField($field, $options); + if ($secure === self::SECURE_SKIP) { + return $result; + } + $fieldName = null; - if ($secure && !empty($options['name'])) { + if (!empty($options['name'])) { preg_match_all('/\[(.*?)\]/', $options['name'], $matches); if (isset($matches[1])) { $fieldName = $matches[1]; } } - $result = parent::_initInputField($field, $options); - if ($secure !== self::SECURE_SKIP) { - $this->__secure($secure, $fieldName); - } + $this->__secure($secure, $fieldName); return $result; } }