summaryrefslogtreecommitdiff
path: root/actions/newnotice.php
diff options
context:
space:
mode:
authorEvan Prodromou <evan@prodromou.name>2008-05-21 07:27:07 -0400
committerEvan Prodromou <evan@prodromou.name>2008-05-21 07:27:07 -0400
commit764a391d196287a9400ee597019c3e5207c5a5f0 (patch)
tree159f2cc26f3c415f67a4da821076865ec9cf6396 /actions/newnotice.php
parent46b3f1c3a746044ae868c06bf3027e0a3ea27433 (diff)
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
Diffstat (limited to 'actions/newnotice.php')
-rw-r--r--actions/newnotice.php19
1 files changed, 11 insertions, 8 deletions
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();
}