On Tue, Apr 24, 2012 at 4:27 PM, Scott Taylor <staylor412@gmail.com> wrote:
> I am having trouble getting an email form to work properly from a
> static page...
> Does anyone know of how to do this?
>
> I have the following in my PageControler::
>
> var $components = array('Email');
> function beforeFilter() {
> parent::beforeFilter();
> $this->Auth->allow('display','email');
> }
>
> function contact(){
>
> $this->layout = 'home';
> $this->set('title_for_layout', 'Home');
> $this->pageTitle = 'Contact Us';
>
> }
>
> function email() {
> if(!empty($this->data)) {
> $this->Page->set($this->data);
>
> if($this->Page->validates()) {
> if(!empty($this->data['Page']['company'])) {
> $this->Email->from = $this->data['Page']
> ['company'] . ' - ' . $this->data['Page']['name'] . ' <' . $this-
>>data['Page']['email'] . '>';
> } else {
> $this->Email->from = $this->data['Page']['name'] .
> ' <' . $this->data['Page']['email'] . '>';
> }
> $this->Email->to = 'staylor412@gmail.com';
> $this->Email->subject = 'Website request';
> $this->Email->send($this->data['Page']['message']);
> $this->Session->setFlash('Your message has been
> sent.');
> // Display the success.ctp page instead of the form
> again
> $this->redirect(array('action'=>'contact'));
>
> } else {
> $this->redirect(array('action'=>'contact'));
>
> }
> }
> }
>
>
> I have the following in my contact.ctp::
>
> <?php echo $this->Form->create('Page', array('action' => 'email')); ?>
> <table class="contact-table">
> <tr>
> <td>Name</td>
> <td><?php echo $this->Form->input('Page.name', array('label'
> => false, 'maxlength' => 100, 'size' => 40)); ?></td>
> </tr>
> <tr>
> <td>Company</td>
> <td><?php echo $this->Form->input('Page.company',
> array('label' => false, 'maxlength' => 100, 'size' => 40)); ?></td>
> </tr>
> <tr>
> <td>E-Mail</td>
> <td><?php echo $this->Form->input('Page.email', array('label'
> => false, 'maxlength' => 100, 'size' => 40)); ?></td>
> </tr>
> <tr>
> <td style="vertical-align: top;">Your comment</td>
> <td><?php echo $this->Form->input('Page.message',
> array('label' => false, 'cols' => 50, 'rows' => 10)); ?></td>
> </tr>
> <tr>
> <td colspan="2" align="center"><br><?php echo $this->Form-
>>end('Send'); ?></td>
> </tr>
> </table>
>
> I created what has to be an unnecessary page model with the
> following::
> class Page extends AppModel {
> var $name = 'page';
> var $useTable = false;
>
> var $validate = array(
> 'name' => array(
> 'rule' => 'notEmpty',
> 'message' => 'You have not entered your name.'
> ),
> 'email' => array(
> 'rule' => 'email',
> 'message' => 'You have entered an invalid e-mail address.'
> ),
> 'message' => array(
> 'rule' => 'notEmpty',
> 'message' => 'You did not enter a message.'
> )
> );
> }
>
> --
> Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
No comments:
Post a Comment