从选择输入提交文本,而不是ID - CakePHP

I have a Select box full of Account names that I retrieve from my CRM with a SOAP call. I send JUST the names to my view when I use the cakePHP FormHelper to create my form. The only issue I'm having is although the select populates properly it sends back the index I've chosen and not the text like i'd like.

echo $this->Form->create();
  echo $this->Form->input('name');
  echo $this->Form->input('email');
  echo $this->Form->input('account');
  echo $this->Form->input('message');
  echo $this->Form->end(__('Submit')); 
echo $this->Form->end();

So does anyone know how to submit the selected value of account and not the ID? Thank you in advance.

if $accounts is the variable name you are using, you can try

$accountValues = array();
foreach ($accounts as $key => $value) {
    $accountValues[$value] = $value;
} 
$accounts = $accountValues;

to generate an array that will have both keys and values the same.

Considering you have an array

$account = array('1'=>'Account Name','2'=>'Account name2',etc);

change the above array into (Value => Value pair)

$account = array('Account Name'=>'Account Name',
                 'Account name2'=>'Account name2',etc);

Assuming you know how to convert $account array into desired input: Then just pass that array in options and you will get value instead of ID.

<?php echo $this->Form->input('account', 
                  array('type'=>'select',
                        'options'=>$account, 
                        'label'=>false, 
                        'empty'=>'Account'));
 ?>

to expand the more cake way to do it is to have an account_id form field

$this->Form->input('account_id');

and then set $accounts from the controller to your view.

In CakePHP 3.X you can do something like this:

// somewhere inside your Controller
$optionList =
   $this->createOptionList(
       $this->Users, ['id', 'name'], 'id', 'name'
   ); 

// a reusable function to create the array format that you needs for your select input
private function createOptionArray($model, $fields, $arrayKey, $arrayValue, $limit = 200) {
   $query = $model
      ->find()
      ->select($fields)
      ->limit($limit);

   $options = array();
   foreach ($query as $key => $value) {
      $options[$value->$arrayKey] = $value->$arrayValue;
   }

   return $options;
}

The function createOptionArray, creates the following array format:

[
    (int) 1 => 'Dennis',
    (int) 2 => 'Frans'
]

Now you can simple add this array inside a Form-input of your view like this:

 <?= $this->Form->input('user_id', ['options' => $optionList, 'empty'=>'Choose']); ?>