What you could possibly do (maybe it's not the best), is to loop on
the single validation of the model by setting your different field
value to it  :

In controller:

$this->Mark->validate = array('mark_number' => your validation);   //
this is required if you have other validations in the Mark model (to
eventually process other validation before)

$fail = false;

for($i = 0; i < $nbmark; $i++)
{
   $this->Mark->data['Mark']['mark_number'] = $this->data['Mark']
['mark_number'.$i];

  if(!$this->Mark->validates())
 {
     $fail = true;
     $this->Mark->invalidate('mark_number'.$i, "Mark already exists);
}
}

if(fail)
{
  $this->render(..)
  exit();
}

hope this helps
On Aug 6, 6:25 pm, nagarjuna <[EMAIL PROTECTED]> wrote:
> I have the following setup:  Class Observation hasMany Marks.
> The Marks Class only has one relevant field: mark_number
> I am working on the add form for my Observations, and the problem is
> that I do not know in advance how many Marks a given observation will
> have.  I initialize the form with one mark field called data['Marks']
> ['mark_number0'], and then if the user has multiple marks he can click
> on a "add another mark" link which dynamically creates a new field
> data['Marks']['mark_number1'] and so on.
> So far so good.  My problem comes to dealing with data validation.
> First, I need to check that each mark_number is unique and doesn't
> already exist in the database and if not I need to invalidate the
> field.  I would like to put the validation routine inside my Mark
> model, but it only has a single field mark_number, and not
> mark_number0, etc, so I cannot invalidate the appropriate field there.
>
> I can code all of this by hand, but it is ugly and feels wrong as if I
> am not taking advantage of all the cakey goodness.  What is the best
> practice way to deal with this situation.
>
> Thanks for any advice


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to