Adding 'before', 'between', and 'after' options to FormHelper::input()

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4298 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2007-01-16 12:54:55 +00:00
parent 6dcdad1a2c
commit 6e56e926e7

View file

@ -261,6 +261,13 @@ class FormHelper extends AppHelper {
function input($tagName, $options = array()) { function input($tagName, $options = array()) {
$this->setFormTag($tagName); $this->setFormTag($tagName);
$options = am(
array(
'before' => null,
'between' => null,
'after' => null
),
$options);
if ((!isset($options['type']) || $options['type'] == 'select') && !isset($options['options'])) { if ((!isset($options['type']) || $options['type'] == 'select') && !isset($options['options'])) {
if (ClassRegistry::isKeySet($this->model())) { if (ClassRegistry::isKeySet($this->model())) {
@ -363,8 +370,11 @@ class FormHelper extends AppHelper {
unset($options['empty']); unset($options['empty']);
} }
$type = $options['type']; $type = $options['type'];
unset($options['type']); $before = $options['before'];
$between = $options['between'];
$after = $options['after'];
unset($options['type'], $options['before'], $options['between'], $options['after']);
switch ($type) { switch ($type) {
case 'hidden': case 'hidden':
@ -372,44 +382,42 @@ class FormHelper extends AppHelper {
unset($divOptions); unset($divOptions);
break; break;
case 'checkbox': case 'checkbox':
$out = $this->Html->checkbox($tagName, null, $options) . $out; $out = $before . $this->Html->checkbox($tagName, null, $options) . $between . $out;
break; break;
case 'text': case 'text':
$out .= $this->text($tagName, $options);
break;
case 'password': case 'password':
$out .= $this->password($tagName, $options); $out = $before . $out . $between . $this->{$type}($tagName, $options);
break; break;
case 'file': case 'file':
$out .= $this->Html->file($tagName); $out = $before . $out . $between . $this->Html->file($tagName);
break; break;
case 'select': case 'select':
$list = array(); $options = am(array('list' => array()), $options);
if(isset($options['options'])) { $list = $options['options'];
$list = $options['options']; unset($options['options']);
unset($options['options']); $out = $before . $out . $between . $this->select($tagName, $list, $selected, $options, $empty);
}
$out .= $this->select($tagName, $list, $selected, $options, $empty);
break; break;
case 'time': case 'time':
$out .= $this->Html->dateTimeOptionTag($tagName, null, '12', $selected, $options, null, $empty); $out = $before . $out . $between . $this->Html->dateTimeOptionTag($tagName, null, '12', $selected, $options, null, $empty);
break; break;
case 'date': case 'date':
$out .= $this->Html->dateTimeOptionTag($tagName, 'MDY', null, $selected, $options, null, $empty); $out = $before . $out . $between . $this->Html->dateTimeOptionTag($tagName, 'MDY', null, $selected, $options, null, $empty);
break; break;
case 'datetime': case 'datetime':
$out .= $this->Html->dateTimeOptionTag($tagName, 'MDY', '12', $selected, $options, null, $empty); $out = $before . $out . $between . $this->Html->dateTimeOptionTag($tagName, 'MDY', '12', $selected, $options, null, $empty);
break; break;
case 'textarea': case 'textarea':
default: default:
$out .= $this->textarea($tagName, am(array('cols' => '30', 'rows' => '10'), $options)); $out = $before . $out . $between . $this->textarea($tagName, am(array('cols' => '30', 'rows' => '10'), $options));
break; break;
} }
if ($error != null) { if ($error != null) {
$out .= $this->Html->tagErrorMsg($tagName, $error); $out .= $this->Html->tagErrorMsg($tagName, $error);
} }
if ($type != 'hidden') {
$out .= $after;
}
if (isset($divOptions)) { if (isset($divOptions)) {
$out = $this->Html->div($divOptions['class'], $out, $divOptions); $out = $this->Html->div($divOptions['class'], $out, $divOptions);
} }