I'm working on a project that has a quick contact form that send
emails to the site owner. The form is in an element and available to
the whole site. I'm using a controller called Mailer to handle this.
Mailer has a model to validate both fields, email and message, and
uses no tables.

If a user fills in both forms and hits send the email is sent and
$this->redirect($this->referer()) takes them back to the page that the
contact form was used on. The problem I'm having is when I add
validation into the mix. I can't redirect back to the sending page and
display validation errors. If I take the redirect out of the picture
then the controller will want to send them to a view, in this case /
mailer/send_email.ctp. The validation errors show up on this page. Is
there anyway to get the validation errors to show up without having a
view? Here is what I've got so far.

Here is my controller code:

    function sendEmail() {
                if($this->Mailer->create($this->data) && 
$this->Mailer->validates())
{
                        $this->Email->to = '[EMAIL PROTECTED]';
                        $this->Email->subject = 'Quick Contact Form';
                        $this->Email->replyTo = '[EMAIL PROTECTED]';
                        $this->Email->from = $this->data['Mailer']['email'];
                        $this->Email->delivery = 'smtp';
                        $this->Email->template = 'contact_notify';

                        //set variables for email message
                        $this->set('email', $this->data['Mailer']['email']);
                        $this->set('message', $this->data['Mailer']['message']);

                        //send email
                        if ($this->Email->send()) {
                                $this->Session->setFlash('Your Message Has Been 
Sent.');
                        } else {
                                $this->Session->setFlash('We Apologize, Your 
Message Could Not Be
Sent At This Time.');
                        }
                        $this->redirect($this->referer());
                }
                else {
                        $this->Session->setFlash('Please Fill in All 
Appropriate Fields.');
                        $this->redirect($this->referer());
                }
    }


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