[pLog-svn] r632 - plog/trunk/class/action
oscar at devel.plogworld.net
oscar at devel.plogworld.net
Thu Dec 30 17:48:39 GMT 2004
Author: oscar
Date: 2004-12-30 17:48:39 +0000 (Thu, 30 Dec 2004)
New Revision: 632
Modified:
plog/trunk/class/action/addcommentaction.class.php
Log:
cleaned up the AddCommentAction::validate() method to make it smaller and to make the whole action class use the form validation framework. Also now when a data validation error happens, it will show all errors at once... It'd be nicer to show the "add comment" form once again but it might unnecessarily overcomplicate the templates.
Modified: plog/trunk/class/action/addcommentaction.class.php
===================================================================
--- plog/trunk/class/action/addcommentaction.class.php 2004-12-30 17:45:47 UTC (rev 631)
+++ plog/trunk/class/action/addcommentaction.class.php 2004-12-30 17:48:39 UTC (rev 632)
@@ -13,6 +13,7 @@
include_once( PLOG_CLASS_PATH."class/dao/articlenotifications.class.php" );
include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
include_once( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
+ include_once( PLOG_CLASS_PATH."class/data/validator/emailvalidator.class.php" );
include_once( PLOG_CLASS_PATH."class/net/client.class.php" );
include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
include_once( PLOG_CLASS_PATH."class/view/errorview.class.php" );
@@ -42,6 +43,23 @@
function AddCommentAction( $blogInfo, $request )
{
$this->BlogAction( $blogInfo, $request );
+
+ // change the validation mode of the form
+ $this->registerFieldValidator( "articleId", new IntegerValidator());
+ $this->_form->setFieldErrorMessage( "articleId", $this->_locale->tr("error_incorrect_article_id" ));
+ $this->registerFieldValidator( "blogId", new IntegerValidator());
+ $this->_form->setFieldErrorMessage( "blogId", $this->_locale->tr("error_incorrect_blog_id" ));
+ $this->registerFieldValidator( "parentId", new IntegerValidator(), true );
+ $this->_form->setFieldErrorMessage( "parentId", $this->_locale->tr("error_incorrect_article_id" ));
+ $this->registerFieldValidator( "userEmail", new EmailValidator(), true );
+ $this->_form->setFieldErrorMessage( "userEmail", $this->_locale->tr("error_incorrect_email_address" ));
+ $this->registerFieldValidator( "userName", new StringValidator());
+ $this->_form->setFieldErrorMessage( "userName", $this->_locale->tr("error_comment_without_name" ));
+ $this->registerFieldValidator( "commentText", new StringValidator());
+ $this->_form->setFieldErrorMessage( "commentText", $this->_locale->tr("error_comment_without_text" ));
+ $view = new ErrorView( $this->_blogInfo );
+ $view->setErrorMessage( "There has been an error validating the data!" );
+ $this->setValidationErrorView( $view );
$this->_fetchFields();
}
@@ -52,31 +70,23 @@
$this->_blogId = $this->_request->getValue( "blogId" );
$this->_opId = $this->_request->getValue( "op" );
$this->_parentId = $this->_request->getValue( "parentId" );
-
$this->_userEmail = trim($this->_request->getValue( "userEmail" ));
$this->_userUrl = trim($this->_request->getValue( "userUrl" ));
if( substr($this->_userUrl, 1, 7 ) != "http://" )
$this->_userUrl = "http://".$this->_userUrl;
$this->_userName = trim($this->_request->getValue( "userName" ));
-
$this->_parentId = $this->_request->getValue( "parentId" );
- if( $this->_parentId == "" )
- $this->_parentId = 0;
-
$this->_commentText = trim($this->_request->getValue( "commentText" ));
$this->_commentTopic = trim($this->_request->getValue( "commentTopic" ));
// remove all straneous stuff from the text and topic
$tf = new TextFilter();
$this->_commentTopic = $tf->xhtmlize($tf->filterHTML( $this->_commentTopic ));
-
// and also from the text
$this->_commentText = $tf->xhtmlize($tf->filterHTML( $this->_commentText ));
-
// now, if the option is set, we 'beautify' the text typed by users
if( $this->_config->getValue( "beautify_comments_text" )) {
$this->_commentText = $tf->autop($this->_commentText);
}
-
}
/**
@@ -95,49 +105,31 @@
return false;
}
-
- // if they are, proceed with everything else
- $this->_fetchFields();
- // we have to check all the important fields first
- $validator = new IntegerValidator();
- if( !$validator->validate( $this->_articleId )) {
- $this->_view = new ErrorView( $this->_blogInfo, "error_incorrect_article_id" );
- $this->setCommonData();
-
- return false;
- }
-
- // check the blog id
- $blogIdVal = new IntegerValidator();
- if( !$blogIdVal->validate( $this->_blogId )) {
- $this->_view = new ErrorView( $this->_blogInfo, "error_incorrect_blog_id" );
- $this->setCommonData();
- return false;
- }
-
- // check the post text
- $strValidator = new StringValidator();
- if( !$strValidator->validate( $this->_commentText )) {
- $this->_view = new ErrorView( $this->_blogInfo, "error_comment_without_text" );
- $this->setCommonData();
- return false;
- }
-
- // check the post owner
- $strUserVal = new StringValidator();
- if( !$strUserVal->validate( $this->_userName )) {
- $this->_view = new ErrorView( $this->_blogInfo, "error_comment_without_name" );
- $this->setCommonData();
- return false;
- }
-
- // sanity check
- if( $this->_parentId == "" || $this->_parentId < 0 )
- $this->_parentId = 0;
-
- // otherwise, we can return everything OK
- return true;
+
+ return( parent::validate());
}
+
+ /**
+ * prepare a nicer error message. This method is only going to be executed whenver a validation
+ * error happens (see Action::validate())
+ *
+ * @see Action::validate()
+ */
+ function validationErrorProcessing()
+ {
+ // collect all the errors from all the fields and for those that failed validation,
+ // put them in a nicer string.
+ $results = $this->_form->getFormValidationResults();
+ foreach( $results as $field => $result ) {
+ if( !$result ) {
+ $errorMessage .= $this->_form->getFieldErrorMessage( $field )."<br/><br/>";
+ }
+ }
+
+ $this->_view->setErrorMessage( $errorMessage );
+
+ return true;
+ }
/**
* Carries out the action
More information about the pLog-svn
mailing list