From 764a391d196287a9400ee597019c3e5207c5a5f0 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 21 May 2008 07:27:07 -0400 Subject: validation in form handlers Moved validation code from classes to form handlers. Probably better in the classes, but I can't quite grok the validate() method in DB_DataObject, so for now I'm going to do it the old-fashioned way. darcs-hash:20080521112707-84dde-38e27199b977ae81171b8391fbdb93ebb54494f9.gz --- actions/newnotice.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'actions/newnotice.php') diff --git a/actions/newnotice.php b/actions/newnotice.php index faf9b21ef..6e6c3ff2c 100644 --- a/actions/newnotice.php +++ b/actions/newnotice.php @@ -49,19 +49,22 @@ class NewnoticeAction extends Action { $notice->profile_id = $user->id; # user id *is* profile id $notice->created = DB_DataObject_Cast::dateTime(); # Default theme uses 'content' for something else - $notice->content = trim($this->arg('noticecontent')); + $notice->content = $this->trimmed('noticecontent'); - $val = $notice->validate(); - if ($val === TRUE) { - return $notice->insert(); - } else { - // XXX: display some info - return NULL; + if (!$notice->content) { + $this->show_form(_t('No content!')); + } else if (strlen($notice->content) > 140) { + $this->show_form(_t('Notice content too long.')); } + + return $notice->insert(); } - function show_form() { + function show_form($msg=NULL) { common_show_header(_t('New notice')); + if ($msg) { + common_element('div', 'error', $msg); + } common_notice_form(); common_show_footer(); } -- cgit v1.2.3-54-g00ecf