Hi  manuj.

Your proposal didn't solve my problem. I think I did read somewhere in
group postings that using fromHelpr->input is the right way for form
fields and using formHelper->select, formHelper->label, ... etc will
be deprecated in next versions of CakePHP. I'm not sure for this and
correct me if I'm wrong.

On Oct 19, 8:06 pm, manuj bansalr <[EMAIL PROTECTED]> wrote:
> i didnt get your code you want select option then why r you going thru
> input function
>
> try it
>
> *************view code********************************
>
> echo $form->label('modelname.name')
> echo $form->select('modelname.name',array('value'=>'text'));
> echo $form->error('it can't be blank');
>
> ***************model code*************************
>
> var
> $validate=array('name'=>VALID_NOT_EMPTY);
>
> IT IS FOR SELECT OPTION
>
> On Oct 19, 9:24 pm, senser <[EMAIL PROTECTED]> wrote:
>
> > 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 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