Wednesday, July 30, 2014

Re: Display Form Validation Errors CakePHP 3

There does not seem to be any Form->create() call in that code you pasted. Can you share the full code?

On Wednesday, July 30, 2014 3:20:54 PM UTC+2, Jipson Thomas wrote:
Hi ,
On my package creation form I am using cakephp validation. The validation is working perfectly. Unfortunately the validation error messages are not displaying on my form. Would you please help me on this?

The code I am using is as follows. Please advise me what I am missing here.

My Table Class

==============
public function validationDefault(Validator $validator) {
        $validator
            ->notEmpty('name','A valid package name is required')
            ->notEmpty('annual_price','A valid annual price is required')
            ->notEmpty('monthly_price','A valid monthly price is required')
            ->notEmpty('duration','Minimum duration of contract is required')
            ->notEmpty('no_partners','Maximum no of partners is required')
            ->notEmpty('no_emails','Maximum no of emails per month is required');

        return $validator;
    }

On my controller

================
I am using the following codes to get the validation result.
$package = $this->Package->newEntity($this->request->data);
if ($this->SubscriptionPackage->save($package)) {
                $this->Flash->success(__('The package has been saved.'));
                return $this->redirect(['action' => 'index']);
            }
            else{
//print_r($package->errors()); It will display an array with field names and message.
}

On my ctp file I am using the following code.
====================================
 <?php echo $this->Form->input('name', ['label' => 'Package Name']); ?>
       <?php echo $this->Form->input('annual_price', ['label' => 'Price / Year','type' => 'decimal']); ?>
       <?php echo $this->Form->input('monthly_price', ['label' => 'Price / Month','type' => 'decimal']); ?>
       <?php echo $this->Form->input('duration', ['label' => 'Minimum Months of Contract','type' => 'integer']);?>
       <?php echo $this->Form->input('no_partners', ['label' => 'Maximum No of Partners','type' => 'integer']);?>
       <?php echo $this->Form->input('no_emails', ['label' => 'Maximum No of Emails/Month','type' => 'integer']);?>
       <?php echo $this->Form->input('storage', ['label' => 'Maximum Allowed Storage Space (GB)','type' =>?>

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: