Search code examples
phpcakephpselectinputform-helpers

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('label'=> 'System ID'));
shows up as a select box no matter where I place it.

How do I resolve this?


Solution

  • 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.