Input showing as a select with cake form helper
I have the following code:
<h2>Add System</h2>
<?php
echo $this->Form->create('ReleaseServer');
echo $this->Form->input('server_name',array('error'=>array(
0 => 'Please choose a system name'),
'label'=>'System Name'
));
echo $this->Form->input('server_id', array('label'=> 'System ID'));
echo $this->Form->select('server_environment', $environments, null, array(
'empty' => "-- Select an Environment --",
'label' => "Select an Environment",
'error' => array(0 => 'Please choose an environment!'),
'onchange'=>'console.log(this.value);'
)
);
echo $this->Form->end('Save System');
?>
For some reason the line
echo $this->Form->input('server_id', array('l开发者_运维技巧abel'=> 'System ID'));
shows up as a select box no matter where I place it.
How do I resolve this?
You could try adding type
to your options array and explicitly defining what you want the input to be.
Edit
After digging around in the Cake API I think I may have found a specific line of code that may be affecting you here.
if (preg_match('/_id$/', $fieldKey) && $options['type'] !== 'hidden') {
$options['type'] = 'select';
}
It appears likely that you are triggering this if
conditional. If so, your only option is to explicitly set the type
attribute in your options array.
Right now I am using a hack:
echo $this->Form->input('server_id', array('label'=> 'System ID',
'type'=>'text'));
I am explicitly setting the type
as text.
I do not have to do that for the other input, but that might be the way it has to be.
Just hide the input if it doesn't matter to show or not. As when inserting mysql will assign it a new id.
echo $this->Form->input('server_id', array('type'=> 'hidden'));
精彩评论