You'll want to put this tag before your $html->radio tag:

<?php echo $html->hidden('Bloodbank/gender', array('value'=>'')); ?>

<label>Gender:</label>
<?php echo $html->radio('Bloodbank/gender',array('Male','Female')) ?>
<?php echo $html->tagErrorMsg('Bloodbank/gender', 'gender is
required') ?>

The reason for this is that if a radio button is not selected, the
value not posted, so you need to have a hidden input with an empty
value in your view so that it will get posted. When the user selects
the radio button, the radio button will override the hidden value. You
can use VALID_NOT_EMPTY in your model's validate var, but also make
sure in your controller that the value is set so that hacker's can't
just delete the hidden input tag.

if(isset($this->data['Bloodbank']['gender'])) {
      $this->invalidate('Bloodbank/gender');
      $this->render();
      exit;
}

// continue onward....

Hope this helps. PHP and forms, especially in regard to checkboxes and
radio buttons, can be very frustrating sometimes.

On Jul 13, 10:26 pm, "salahuddin pasha (salahuddin66)"
<[EMAIL PROTECTED]> wrote:
> hello there,
>
> I am trying to validate radio (where I did not set any default value)
>
> <label>Gender:</label>
> <?php echo $html->radio('Bloodbank/gender',array('Male','Female')) ?>
> <?php echo $html->tagErrorMsg('Bloodbank/gender', 'gender is
> required') ?>
>
> in model
> --------
> var $validate = array(
>                 'gender' => VALID_NUMBER,
>                 .....
> )
>
> i also tried with VALID_NOT_EMPTY
>
> But is seems that I dont get tagErrorMsg, when none is selected.
>
> --
> --salahuddin66
>
> salahuddin66.blogspot.com
> salahuddin66.deviantart.com
>
>  signature.asc
> 1KDownload


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to