Hi there!
I'm trying to write a code for displaying a select box with several
options (tax years for example) and I have to validate the data passed
by that select box. I want the user to must select an option from the
list.
Here is the code from view file where I populate the box using
formHelper:
/****************CODE**************************/
print $form->input('CustomerTaxYear.tax_years_id',
array('type'=>'select', 'label'=>'Tax Year', 'options'=>
$taxYearsArray, 'size'=>3,'error'=>array('required'=>'Tax Year is
obligatory', 'maxlength'=>'Tax year code max length is 3 symbols',
'number'=>'Tax year code must be a number')));
/****************CODE_END********************/
and here is the part of validation array:
/****************CODE**************************/
var
$validate=array( 'tax_years_id'=>array('required'=>VALID_NOT_EMPTY,
'maxlength'=>array('rule'=>array('between',1,3)),
'number'=>VALID_NUMBER));
/****************CODE_END********************/
The result is that if the user doesn't select an element from the
select box, there is no error message displayed and the validation is
passed but the form data is not stored in DB, because the field
"tax_years_id" doesn't have default value which is correct behaviour.
I've tried with 'showEmpty' set to true but with no success. If there
is no value selected in select box, the passed array doesn't even have
an a element called 'tax_years_id'. (i make a dump of $this->data and
in the array element with name 'tax_years_id' is missing). I've also
tried to make an empty element and select it by default, but I think
this is "ugly" approach, because if user selects some tax year but
form validation fails by reason of other wrong filled field and
selected element in tax year select box is lost.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---