I have to validate multiple model in single form using 'CakePHP'. I have 2 models.
Invoice
public $validate = array(
'type' => array(
'rule' =>'notEmpty',
'message' => 'Select Invoice Type.',
'required' => true
),
'number' => array(
'rule' =>'numeric',
'message' => 'Enter Invoice Number.',
'required' => true
),
'date' => array(
'rule' => array('date', 'dmy'),
'allowEmpty' => true,
'message' => 'Enter Invoice Date.'
),
);
public $belongsTo = array(
'Client' => array(
'className' => 'Client',
'foreignKey' => 'client_id'
));
Client
public $validate = array(
'name' => array(
'rule' =>'notEmpty',
'message' => 'Enter Your Name.',
'required' => true
),
'company' => array(
'rule' =>'notEmpty',
'message' => 'Enter Your Company Name.',
'required' => true
),
'address' => array(
'rule' =>'notEmpty',
'message' => 'Enter Your address.',
'required' => true
)
);
public $hasMany = 'Invoice';
And I have one form with Fields like 'clientName', 'Address', 'InvoiceNumber' and 'InvoiceDate'.
I have used saveAll(), but it is only validating Invoice
data and not the Client
data.