CakePHP - radio button not showing error message
I'm unable to get the error message to show up when creating a radio form using the CakePHP form helper.
This is what I have now.
$options开发者_开发百科=array('active'=>'Active','inactive'=>'Inactive');
echo $form->input('Status', array(
'type' => 'radio',
'id' => 'EntryStatus',
'name' => 'data[Entry][status]',
'options' => $options
));
What am I missing?
I'm using CakePHP 1.2.7 and this is what I have in the validation'status' => array(
'notempty' => array(
'rule' => 'notempty',
'required' => true,
'message' => 'yo'
)
)
Tried the answer from Form helper for creating Radio button in Cakephp and it's giving me a select option form instead.
Thanks,
Teehad same problem, and i fount this, and it works:
http://book.cakephp.org/view/204/Form-Element-Specific-Methods
you need
if ($form->isFieldError('gender')){
echo $form->error('gender');
}
... in your code. this works in case that your field is named as gender.
I had the same issue and I added:
<?php echo $form->error('currentStatus');?>
below the radio button and it worked fine.
Try taking a look at $form->input('Status' ... (capital 'Status') versus the DB column name (which might or might not be capitalized versus 'name' => 'data[Entry][status]' (not capital 'status').
Cake's form helper is picky about inserting error messages when it can't figure out what things go to what.
Have you tried using the explicit $form->radio() method instead of the general input() method?
You need to manually add in an error form helper.
echo $form->error('status');
You need to add error condition in case of radio button
<?php
$options=array('active'=>'Active','inactive'=>'Inactive');
echo $form->input('Status', array(
'type' => 'radio',
'id' => 'EntryStatus',
'options' => $options
)
);
if ($form->isFieldError('Status')){
echo $form->error('Status');
}
?>
精彩评论