Adding automatic list variable detection for select menus, and 'default' => false option for preventing form submits via JavaScript

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4113 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2006-12-21 04:46:52 +00:00
parent fd9a347fe1
commit 3c023b4335

View file

@ -121,6 +121,18 @@ class FormHelper extends AppHelper {
$htmlAttributes['method'] = 'post';
break;
}
if (isset($options['default'])) {
if ($options['default'] == false) {
if (isset($htmlAttributes['onSubmit'])) {
$htmlAttributes['onSubmit'] .= ' return false;';
} else {
$htmlAttributes['onSubmit'] = 'return false;';
}
}
unset($options['default']);
}
$htmlAttributes['action'] = $this->url($options['action']);
unset($options['type'], $options['action']);
$htmlAttributes = am($options, $htmlAttributes);
@ -223,6 +235,24 @@ class FormHelper extends AppHelper {
$this->setFormTag($tagName);
if (!isset($options['type']) || ($options['type'] == 'select' && !isset($options['options']))) {
if (ClassRegistry::isKeySet($this->model())) {
$model =& ClassRegistry::getObject($this->model());
if ($model->isForeignKey($this->field())) {
$view =& ClassRegistry::getObject('view');
$varName = Inflector::variable(Inflector::pluralize(preg_replace('/_id$/', '', $this->field())));
$varOptions = $view->getVar($varName);
if (is_array($options)) {
$options['type'] = 'select';
$options['options'] = $varOptions;
}
}
}
}
if (!isset($options['type'])) {
$options['type'] = 'text';