diff options
author | Bharat Mediratta <bharat@menalto.com> | 2010-05-14 16:19:53 -0700 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2010-05-14 16:19:53 -0700 |
commit | ad0e7254eb6e6a763c9b4d0a7252dc5982a814be (patch) | |
tree | f79887f228374640ab2cc80f3c638fc3eb62e1b4 /modules/comment/models | |
parent | 9affa8ebbd539396d71f19003b91af577a8a183e (diff) |
Require a well-formed email address for all comments.
Diffstat (limited to 'modules/comment/models')
-rw-r--r-- | modules/comment/models/comment.php | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/modules/comment/models/comment.php b/modules/comment/models/comment.php index 48084340..fb70c79a 100644 --- a/modules/comment/models/comment.php +++ b/modules/comment/models/comment.php @@ -61,7 +61,7 @@ class Comment_Model extends ORM { if (!$array) { $this->rules = array( "guest_name" => array("callbacks" => array(array($this, "valid_author"))), - "guest_email" => array("rules" => array("email")), + "guest_email" => array("callbacks" => array(array($this, "valid_email"))), "guest_url" => array("rules" => array("url")), "item_id" => array("callbacks" => array(array($this, "valid_item"))), "state" => array("rules" => array("Comment_Model::valid_state")), @@ -145,6 +145,19 @@ class Comment_Model extends ORM { } /** + * Make sure that the email address is legal. + */ + public function valid_email(Validation $v, $field) { + if ($this->author_id == identity::guest()->id) { + if (empty($v->guest_email)) { + $v->add_error("guest_email", "required"); + } else if (!valid::email($v->guest_email)) { + $v->add_error("guest_email", "invalid"); + } + } + } + + /** * Make sure we have a valid associated item id. */ public function valid_item(Validation $v, $field) { |