Skip to content

Commit

Permalink
Starting to update FormHelper's internals to work with changes in
Browse files Browse the repository at this point in the history
Helper.
  • Loading branch information
markstory committed Jun 25, 2011
1 parent 3a847ae commit b7e554f
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions lib/Cake/View/Helper/FormHelper.php
Expand Up @@ -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']]) &&
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down Expand Up @@ -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']);
}

Expand Down Expand Up @@ -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;
}
}

0 comments on commit b7e554f

Please sign in to comment.