Created
August 9, 2010 15:01
-
-
Save shadowhand/515535 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $data = Validate::factory($_POST) | |
| // CSRF protection | |
| // ->rule('security_token', 'Security::check') | |
| // Real name | |
| ->filter('name', 'trim') | |
| ->rule('name', 'not_empty') | |
| ->rule('name', 'regex', array('/^[\pL .,]++$/u')) | |
| // Email address | |
| ->filter('email', 'trim') | |
| ->rule('email', 'not_empty') | |
| ->rule('email', 'email') | |
| // Feedback content | |
| ->filter('feedback', 'Security::xss_clean') | |
| ->filter('feedback', 'strip_tags') | |
| ->rule('feedback', 'not_empty'); | |
| if ($data->check()) | |
| { | |
| // Convert the feedback into simple HTML | |
| $data['feedback'] = Text::auto_p(Text::auto_link($data['feedback'])); | |
| $body = Walrus::simple('layout/email', array( | |
| 'message' => 'communication/email/feedback', | |
| )) | |
| ->set('title', 'Loosecubes Feedback') | |
| ->set('data', $data->as_array()); | |
| $message = Swift_Message::newInstance("Feedback from {$data['name']}") | |
| ->setFrom(array( | |
| $data['email'] => $data['name'], | |
| )) | |
| ->setTo(array( | |
| '[email protected]' => 'John Smith', | |
| )) | |
| ->setBcc(array( | |
| '[email protected]' => 'Hello World', | |
| )) | |
| ->setBody($body, 'text/html') | |
| ->addPart(strip_tags($body), 'text/plain'); | |
| if ($this->send_email($message)) | |
| { | |
| // Redirect to avoid issues with refresh after POST | |
| $this->request->redirect($this->request->uri().'?status=sent'); | |
| } | |
| } | |
| $errors = $data->errors('communication/feedback'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment