That was it! So simple when you know how.

Many thanks John.

Regards

David

On Jun 5, 8:04 am, John Andersen <[email protected]> wrote:
> Try to remove the redirect in the else statement!
>    John
>
> On Jun 5, 9:56 am, DavidH <[email protected]> wrote:
>
> > Hi
>
> > I'm using CakePHP version 1.2.3.8166 running and PHP 5.2.9.
>
> > I've been following the blog tutorial on the CakePHP site and adapting
> > it for my own basic project. I've got to the bit where the tutorial
> > introduces data validation. I know the validation fails or passes; but
> > for some reason I just can't get it to display error messages in the
> > form.
>
> > Here's my controller add method for adding a new record:
>
> >  function add()
> >     {
> >         // If we have some data to save
> >         if (!empty($this->data))
> >         {
> >             if ($this->Birdfamily->save($this->data))
> >             {
> >                 $this->Session->setFlash('Your bird family has been
> > saved', true);
> >                 $this->redirect(array('action' => 'index'));
> >             }
> >             else
> >             {
> >                 $this->Session->setFlash('Your bird family has NOT
> > been saved', true);
> >                 $this->redirect(array('action' => 'add')); // If there
> > was a problem then go back to the form
> >             }
>
> >         }
> >     }
>
> > Here is my add.ctp view:
>
> > <h1>Add A Bird Family</h1>
>
> > <?php
>
> >     echo $form->create('Birdfamily');
> >     echo $form->input('english_name');
> >     echo $form->error('english_name');
> >     echo $form->input('latin_name');
> >     echo $form->error('latin_name');
> >     echo $form->input('tax_order');
> >     echo $form->error('tax_order');
> >     echo $form->end('Save Bird Family');
>
> > ?>
>
> > and, finally, here is my model with the validation:
>
> > class Birdfamily extends AppModel
> > {
> >         var $name = 'Birdfamily';
>
> >     // Set up validation for Bird Families
> >     var $validate = array(
> >         'english_name' => array(
> >             'rule' => 'alphaNumeric',
> >             'required' => true,
> >             'allowEmpty' => false,
> >             'message' => 'All fields are required'
> >         ),
> >         'latin_name' => array(
> >             'rule' => 'alphaNumeric',
> >             'required' => true,
> >             'allowEmpty' => false,
> >             'message' => 'All fields are required'
> >         ),
> >         'tax_order' => array(
> >             'rule' => 'alphaNumeric',
> >             'required' => true,
> >             'allowEmpty' => false,
> >             'message' => 'All fields are required'
> >         )
>
> >     );
>
> > }
>
> > All very basic stuff I'm sure you'll agree.
>
> > If I submit an empty form it returns to the form with the correct
> > flash message; but why doesn't it display any of the messages saying
> > 'All fields are required'?
>
> > Regards
>
> > David
--~--~---------~--~----~------------~-------~--~----~
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