I have a form that won't save data because of a validation error, but
the validation errors are not appearing in the form. The flash message
that the data could not be saved appears, but not the individual error
messages. I think I've got everything set up the same way that I did
for another form that is working correctly, but obviously missing
something.

The Model:

class PrivateMessage extends AppModel {

        var $name = 'PrivateMessage';

        /* Validations */
   var $validate = array(
        'subject' => array(
            'rule' => array('minLength', '1'),
            'required' => true,
            'allowEmpty' => false,
            'message' => 'Please provide a subject.'
        ),
        'message' => array(
            'rule' => array('minLength', '1'),
            'required' => true,
            'allowEmpty' => false,
            'message' => 'Please write a message.'
        )
        );

Part of the controller:

        function reply($to=null,$reply_to=null,$message_type='reply') {
                // reply_to is the id of the message being replied to

                // if $this->data is not empty, write the message to the 
database
and redirect
                if (!empty($this->data)) {
                        $this->PrivateMessage->create();
                        // The message will be from the current member
                        $this->data['PrivateMessage']['from_member_id'] = 
$this->Session-
>read('Auth.Member.id');
                        if ($this->PrivateMessage->save($this->data)) {
                                $this->Session->setFlash(__('Your message has 
been sent.', true));
                                $this->redirect(array('action'=>'index'));
                        } else {
                                pr($this->data); // this is showing that the 
data has a blank
subject
                                $this->Session->setFlash(__('Your message could 
not be sent.
Please, try again.', true));
                        }
                }

....

        }


Part of the view (reply.ctp):

<div class="privateMessages form">

<?php echo $form->create('PrivateMessage', array('action' =>
'reply'));?>
<?php $session->flash(); ?>
        <fieldset>
                <legend><?php __('Send '.$message_header);?></legend>
        <?php
                echo $form->hidden('to_member_id',array('value'=>$to));
                echo $form->hidden('is_reply_to_message_id',array('value'=>
$reply_to));
                echo $form->input('subject',array('value'=>$subject));
                echo $form->input('message');

        ?>
        </fieldset>
<?php echo $form->end('Send message');?>

</div>

pr($form);
?>



The pr($form) in the view shows no validation errors, but the form
does not save (correctly) when I leave the subject or message blank.

Any help or suggestions on where to look for more help would be much
appreciated.

thank you.
--~--~---------~--~----~------------~-------~--~----~
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