jacknad
jacknad

Reputation: 13739

How to set cakephp radio-button from mysql?

This cakephp form used to edit a mysql record needs to load the state of a radio button from a mysql database. The mysql payment_type is enum('Account', 'Credit'). All of the other non-radio-button form inputs reload from the database and payment_type is correctly displayed on another form using this:

<?php echo h($purchaseOrder['PurchaseOrder']['payment_type']); ?>

Why doesn't this correctly set the radio-button from payment_type?

$options = array('account' => 'Account', 'credit' => 'Credit');
$attributes = array('legend' => false, 'value' => 'payment_type');
echo $this->Form->radio('payment_type', $options, $attributes);

Upvotes: 0

Views: 2104

Answers (1)

Kapil
Kapil

Reputation: 1810

In your attribute array, you should assign value which you want to keep selected by default .

For example you want account to be selected by default then in value you should assign 'account'. So your final attribute will be:

$attributes = array('legend' => false, 'value' => 'account');

Upvotes: 1

Related Questions