Browse Source

Changed the validation method to skip empty inputs

Michael Francis 14 years ago
parent
commit
0a2da261e9
2 changed files with 19 additions and 3 deletions
  1. 9 2
      controllers/AnimelistController.php
  2. 10 1
      models/Entry.php

+ 9 - 2
controllers/AnimelistController.php

@@ -7,6 +7,7 @@ use app\models\User;
 use app\models\Anime;
 use app\models\Entry;
 use \lithium\security\Auth;
+use \lithium\util\Validator;
 
 
 class AnimeListController extends \lithium\action\Controller {
@@ -81,6 +82,7 @@ class AnimeListController extends \lithium\action\Controller {
 		{
 			//Create an entry with the data
 			$entry = Entry::create($this->request->data);
+		
 
 			//Get the current user
 			$user = Auth::check('default');
@@ -93,11 +95,16 @@ class AnimeListController extends \lithium\action\Controller {
 				unset($this->request->data['tags']);
 			}
 			
+			/*
+			var_dump($entry->_validates);
 			//If the entry is valid
-			if ($entry->validates()) {
-				//Store it, :TODO: make sure this passes at some point, silent failure sucks
+			if (Validator::check($entry->data(),$entry->_validates, array('skipEmpty' => true))) {
+				//Store it, :TODO: make sure this passes at some point, silent failures suck
 				$entry->add($username);
+				*/
 
+			if($entry->add($username))
+			{
 				//Redirect the user to their anime list
 				return $this->redirect("/animelist/view/$username");	
 			}

+ 10 - 1
models/Entry.php

@@ -3,6 +3,8 @@
 namespace app\models;
 
 use app\models\Users;
+use \MongoDate;
+use lithium\util\Validator;
 
 Class entry extends \lithium\data\Model {
 	public static function __init() {
@@ -48,7 +50,14 @@ Class entry extends \lithium\data\Model {
 		$entity->created_on = new MongoDate();
 		$entity->updated_on = new MongoDate();
 		$user->animelist[] = $entity;
-		return $user->save(null, array('validate' => false));
+
+		if (Validator::check($entity->data(), $this->validates, array('skipEmpty' => 'true'))) {
+			return $user->save(null, array('validate' => false));
+		}
+		else 
+		{
+			return false;
+		}
 	}
 
 	public function edit($entity, $username)