Jump to content

Views not displaying error message


Dharmender

Recommended Posts

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!');
					 }
				 }
				 }
			 }


Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.