Jump to content


Photo

Views not displaying error message

models views errors

  • Please log in to reply
No replies to this topic

#1 Dharmender

Dharmender

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts
  • LocationDelhi, India

Posted 11 February 2013 - 06:15 AM

View is not displaying error messages.Validation done at model level

My view is add.ctp
<?php
echo $this->Session->Flash();

foreach($this->form->validationerrors as $errors)
{
	 echo $errors['Publishers'];
}

if(isset($updates))
{
	 $id=$updates['Agreement']['id'];
	 $pubname=$updates['Agreement']['publisherid'];
}
echo $this->Form->create('Agreement', array('action' => 'add', 'type' => 'file'));
//echo $this->Form->file('File');
echo "<table><tr><td>Publisher Name</td><td>".$this->Form->input('Publishers',array('label'=>false,'default'=>@$pubname))."</td></tr>";
echo "<tr><td>Agreement File</td><td>".$this->Form->file('File',array('label'=>false))."</td></tr>";
	 echo "<tr><td colspan='2'>".$this->Form->input('id',array('label'=>false,'default'=>@$id,'type'=>'hidden'))."</td></tr>";
echo "<tr><td colspan='2'>".$this->Form->submit('Upload',array('label'=>false,'after' => $this->Html->link('Cancel', array('action' => 'view'))))."</td></tr></table>";

echo $this->Form->end();
?>

Model is
<?php
//License Agreements
//Created By Dharmender On 8-2-2013
class Agreement extends AppModel
{
var $name = 'Agreement';
var $validate=array(
		 'Publishers' => array(
			 'rule' => 'notEmpty',
		 'message' => 'Please enter publisher name.'
	 ));

}
?>

Controller is
<?php
class AgreementsController extends AppController {

var $name = 'Agreements';
var $components = array('Session');
	
function add($id=null)
{
	 if($id!=null)
	 {
		 $updates=$this->Agreement->findById($id);
		 $this->set('updates',$updates);
	 }

	 if(@$this->request->data['Agreement']['id']==NULL)
	 {
					 $this->Agreement->create();
				 if (!empty($this->request->data) &&
					 is_uploaded_file($this->request->data['Agreement']['File']['tmp_name']))
					 {
					 $fileData = fread(fopen($this->request->data['Agreement']['File']['tmp_name'], "r"),
											 $this->request->data['Agreement']['File']['size']);
					 $this->request->data['Agreement']['name'] = $this->request->data['Agreement']['File']['name'];
					 $this->request->data['Agreement']['type'] = $this->request->data['Agreement']['File']['type'];
					 $this->request->data['Agreement']['size'] = $this->request->data['Agreement']['File']['size'];
					 $this->request->data['Agreement']['data'] = $fileData;
					 if($this->request->data['Agreement']['Publishers']=='ram')
						 {
						 $id2=1;
						 }
						 else
						 {
							 $id2=2;	
						 }
					 $this->request->data['Agreement']['publisherid']=$id2;
					 $this->request->data['Agreement']['createdon'] = date ('Y-m-d H:i:s');
					 if($this->Agreement->save($this->data))
					 {
							 $this->Session->setFlash('File Uploaded Successfully!');
							 $this->Redirect('view');
						 }
						 else
						 {
							 $this->Session->setFlash('Error in File Uploading!');
					 }
					 }
			 }
	 else
	 {
					 $this->Agreement->id=$this->request->data['Agreement']['id'];
					 if (!empty($this->request->data) &&
						 is_uploaded_file($this->request->data['Agreement']['File']['tmp_name'])) {
						 $fileData = fread(fopen($this->request->data['Agreement']['File']['tmp_name'], "r"),
												 $this->request->data['Agreement']['File']['size']);
						 $this->request->data['Agreement']['name'] = $this->request->data['Agreement']['File']['name'];
						 $this->request->data['Agreement']['type'] = $this->request->data['Agreement']['File']['type'];
						 $this->request->data['Agreement']['size'] = $this->request->data['Agreement']['File']['size'];
						 $this->request->data['Agreement']['data'] = $fileData;
						 if($this->request->data['Agreement']['Publishers']=='ram')
						 {
						 $id2=1;
						 }
						 else
						 {
							 $id2=2;	
						 }
						 $this->request->data['Agreement']['publisherid']=$id2;
						 $this->request->data['Agreement']['createdon'] = date ('Y-m-d H:i:s');
						 if($this->Agreement->save($this->data))
						 {
							 $this->Session->setFlash('Record Updated Successfully!');
							 $this->Redirect('view');
						 }
						 else
						 {
							 $this->Session->setFlash('Error in File Updating!');
						 }
					 }
					 }
				 }
		
	

Edited by Dharmender, 11 February 2013 - 06:15 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com