>    First, set the data to the model:
>
>    $this->ModelName->set( $this->data );
>
>      $this->ModelName->set( $this->data );
>
>    Then, to check if the data validates, use the validates method of the
>
>    model, which will return true if it validates and false if it doesn't:
>
>      if ($this->ModelName->validates()) {
>         // it validated logic
>      } else {
>         // didn't validate logic
>      }
>
> If it validates, then save the data ...

Thank you very much, that did the trick!

It seems a bit confusing how $this->Model->validates($this->data)
doesn't work, but $this->Model->set($this->data) and $this->Model-
>validates() does, so thanks for clarifying.

Just for posterity, now I'm doing this, and it works like a charm:

      if (!empty($this->data)) {
        // The user's submitting her new record
        $this->Model->set($this->data);

        if ($this->Model->validates()) {
          // The main record hypothetically would add just fine

          if ($this->Model->RelatedModel->save($this->data)) {
            // The related record added just fine

            // Actually add the main record
            $this->Model->save($this->data));
            $this->Session->setFlash("{$this->data['Model']['name']}
has been added.");
            $this->redirect("wherever");
            exit();
          } else {
            // The related record wouldn't save
            $this->Session->setFlash("Sorry, {$this->data['Model']
['name']} couldn't be added.");
          }
        } else {
          // The main record wouldn't hypothetically save
          $this->Session->setFlash("Sorry, {$this->data['Model']
['name']} couldn't be added.");
        }
      }

Thanks for your help, and I hope that clarifies things a bit for
anyone else trying to do the same thing!

Zoe.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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