form, when it is invalid in any way and when a submission is
successful:
Not Found
Error: The requested address '/contacts/add' was not found on this
server.
On a successful submission the e-mail is sent, but it still results in
the above message. I have added a redirect to my controller to
redirect back to the page, but no error messages are displayed
accordingly. I have added $form->error('Contact.name').. etc but they
do not display the messages defined in my model.
I do not have a view file for the controllers action and I just want
to call the method then go back to the initial page and display the
appropriate error messages.
View
<?php echo $form->create('Contact'); ?>
<? echo $form->input('Contact.name'); //text ?>
<? echo $form->input('Contact.email'); //text ?>
<? echo $form->input('Contact.comment', array('rows' => '8',
'cols' => '44')); ?>
<?php echo $form->end('add'); ?>
Controller
<?php
class ContactsController extends AppController {
var $name = 'Contacts';
var $components = array('RequestHandler', 'Email');
var $helpers = array('Html','Ajax','Javascript');
var $uses = array('Contact');
var $msg = null;
function add() {
if ($this->RequestHandler->isPost()) {
$this->Contact->set($this->data);
if ($this->Contact->validates())
{
$Name = $this->data['Contact']['name']; //senders name
$email = $this->data['Contact']['email']; //senders
e-mail adress
$recipient = "EMAIL ADDRESS"; //recipient
$mail_body = $this->data['Contact']['comment']; //mail
body
$subject = 'Contact message from ' . $this->data
['Contact']['name']; //subject
$header = "From: ". $Name . " <" . $email . ">\r\n"; //
optional headerfields
mail($recipient, $subject, $mail_body, $header); //
mail command :)
}
}
}
}
?>
Model
<?php
class Contact extends AppModel {
var $name = 'Contact';
var $useTable = false;
var $_schema = array(
'name' => array('type'=>'string', 'length'=>100),
'email' => array('type'=>'string', 'length'=>255),
'comment' => array('type'=>'text')
);
var $validate = array(
'name' => array('rule' => array('minLength', 1), 'message' =>
'enter your name'),
'email' => array('rule' => 'email', 'message' => 'Must be a valid
email address'),
'comment' => array('rule' => array('minLength', 1), 'message' =>
'Comment is required'));
}
?>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en
-~----------~----~----~----~------~----~------~--~---
No comments:
Post a Comment