tags:

views:

31

answers:

1

My controller action is:

function add() {
if (!empty($this->data)) { $this->Customer->create(); if ($this->Customer->save($this->data)) { $this->Session->setFlash('A new Customer has been added'); $this->redirect(array('action'=>'index')); } else {
$this->Session->setFlash('The customer cannot be added this time. Try again later.'); $this->redirect(array('action'=>'index')); } } }

My model is:

class Customer extends AppModel {

var $name = 'Customer'; var $validate = array( 'name' => array( 'length'=> array( 'rule' => array('between', 4,50), 'message' => 'Name must be minimum 4 and maximum 50 characters long.'
),
'checkUnique'=> array( 'rule' => 'isUnique', 'message' => 'This Name is already registered'
) ));

and this is my view:

create('Customer',array('action'=>'add'));?> input('Customer.name'); echo $form->input('Customer.balance',array('type'=>'hidden','default'=>0)); ?> end('Submit');?>

every time I submit the form it splashes: The customer cannot be added this time. Try again later.

A: 

For the hidden input field use 'value' instead of 'default' in your view:

$form->input('Customer.balance', array('type' => 'hidden', 'value' => 0));
bancer