1

I'm trying to use the build-in validation in cakephp 2.5

My problem is, with text fields I've got the nice jquery error message but for a select field, the message appear in a div. I don't know if I'm missing something in my select to get the error box or it's just not available for that type of field.

screenshot

<?php echo $this->Form->label('launch', 'Launching Site <span class="crRed">*</span>', 'crLabel');?>
<?php echo $this->Form->input('launch', array('label' => false, 'div' => false, 'class'=>'crText crW320 crRequired'));?>

<?php echo $this->Form->label('pfd_c', 'Personal Flotation Device <span class="crRed">*</span>', 'crLabel');?>
<?php echo $this->Form->input('pfd_c', array('type'=>'select', 'options'=>array(0, 1, 2), 'label' => false, 'div' => false, 'class'=>'crLegendText3'));?>
<?php echo $this->Form->input('pfd_p', array('type'=>'select', 'options'=>array(0 => 'No', 1 => 'Yes'), 'label' => false, 'div' => false, 'class'=>'crLegendText3'));?>

Thx

1 Answer 1

1

First of all, this is not a jQuery error message at all, this is an html5 required attribute: http://www.w3schools.com/tags/att_input_required.asp

Sometimes CakePHP can set it automaticaly from validation rules. If it is not, then you can set it manualy by puting 'required'=>true in your options array. Here is a solution for your example:

<?php echo $this->Form->input('pfd_c', array('type'=>'select', 'options'=>array(0, 1, 2), 'label' => false, 'div' => false, 'class'=>'crLegendText3', 'required'=>true));?>

But keep notice that not all browsers supports required attribute, so you may want to leave an div error messages for these browsers.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.