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.* > > Form->input('name', ['label' => 'Package Name']); ?> >Form->input('annual_price', ['label' => 'Price / > Year','type' => 'decimal']); ?> >Form->input('monthly_price', ['label' => 'Price / > Month','type' => 'decimal']); ?> >Form->input('duration', ['label' => 'Minimum > Months of Contract','type' => 'integer']);?> >Form->input('no_partners', ['label' => 'Maximum > No of Partners','type' => 'integer']);?> >Form->input('no_emails', ['label' => 'Maximum No > of Emails/Month','type' => 'integer']);?> >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+unsubscr...@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.
Re: Display Form Validation Errors CakePHP 3
Hi Jose Lorenzo, Thank you for the reply. Please find the below code *CTP* == Flash->render('auth') ?> Form->create() ?> Form->input('name', ['label' => 'Package Name']); ?> Form->input('annual_price', ['label' => 'Price / Year','type' => 'decimal']); ?> Form->input('monthly_price', ['label' => 'Price / Month','type' => 'decimal']); ?> Form->input('duration', ['label' => 'Minimum Months of Contract','type' => 'integer']);?> Form->input('no_partners', ['label' => 'Maximum No of Partners','type' => 'integer']);?> Form->input('no_emails', ['label' => 'Maximum No of Emails/Month','type' => 'integer']);?> Form->input('storage', ['label' => 'Maximum Allowed Storage Space (GB)','type' => 'integer']);?> Form->input('resource_library', ['label' => 'Resource Library','type' => 'checkbox','value' => 'Y','hiddenField' => 'N']);?> Form->input('portal_cms', ['label' => 'Portal CMS','type' => 'checkbox','value'=>'Y','hiddenField' => 'N']);?> Form->input('MDF', ['type' => 'checkbox','value' => 'Y','hiddenField' => 'N']);?> Form->input('deal_registration', ['type' => 'checkbox','value' => 'Y','hiddenField' => 'N']);?> Form->input('partner_recruit', ['type' => 'checkbox','value' => 'Y','hiddenField' => 'N']);?> Form->input('training', ['type' => 'checkbox','value' => 'Y','hiddenField' => 'N']);?> Form->input('Socialmedia', ['type' => 'checkbox','value' => 'Y','hiddenField' => 'N']);?> Form->input('multilingual', ['type' => 'checkbox','value' => 'Y','hiddenField' => 'N']);?> Form->input('partner_incentive', ['type' => 'checkbox','value' => 'Y','hiddenField' => 'N']);?> Form->input('partner_app', ['type' => 'checkbox','value' => 'Y','hiddenField' => 'N']);?> Form->button(__('Save')); ?> Form->end() ?> *Controller Action* == public function add(){ $package = $this->Package->newEntity($this->request->data); if ($this->request->is('post')) { if ($this->Package->save($package)) { $this->Flash->success(__('The package has been saved.')); return $this->redirect(['action' => 'index']); } else{ // $errors = $this->Package->errors(); $error_string= implode('\n',$package->errors()); //print_r($package); } $this->Flash->error(__('Unable to add the package.')); } $this->set('package', $package); } *Model - Table Class* = class PackagesTable extends Table { public function initialize(array $config) { $this->addBehavior('Timestamp', [ 'events' => [ 'Model.beforeSave' => [ 'created_on' => 'new', 'modified_on' => 'always', ] ] ]); } 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; } } Regards, Jipson On Wednesday, 30 July 2014 14:20:54 UTC+1, 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 disp
Re: Display Form Validation Errors CakePHP 3
Ok, you problem is that you are calling create() without the entity, You should get that fixed by doing: Form->create($package) ?> On Wednesday, July 30, 2014 3:29:33 PM UTC+2, Jipson Thomas wrote: > > Hi Jose Lorenzo, > Thank you for the reply. Please find the below code > > *CTP* > == > > Flash->render('auth') ?> > Form->create() ?> > > ?> >Form->input('name', ['label' => 'Package Name']); > ?> >Form->input('annual_price', ['label' => 'Price / > Year','type' => 'decimal']); ?> >Form->input('monthly_price', ['label' => 'Price / > Month','type' => 'decimal']); ?> >Form->input('duration', ['label' => 'Minimum > Months of Contract','type' => 'integer']);?> >Form->input('no_partners', ['label' => 'Maximum > No of Partners','type' => 'integer']);?> >Form->input('no_emails', ['label' => 'Maximum No > of Emails/Month','type' => 'integer']);?> >Form->input('storage', ['label' => 'Maximum > Allowed Storage Space (GB)','type' => 'integer']);?> >Form->input('resource_library', ['label' => > 'Resource Library','type' => 'checkbox','value' => 'Y','hiddenField' => > 'N']);?> >Form->input('portal_cms', ['label' => 'Portal > CMS','type' => 'checkbox','value'=>'Y','hiddenField' => 'N']);?> >Form->input('MDF', ['type' => 'checkbox','value' > => 'Y','hiddenField' => 'N']);?> >Form->input('deal_registration', ['type' => > 'checkbox','value' => 'Y','hiddenField' => 'N']);?> >Form->input('partner_recruit', ['type' => > 'checkbox','value' => 'Y','hiddenField' => 'N']);?> >Form->input('training', ['type' => > 'checkbox','value' => 'Y','hiddenField' => 'N']);?> >Form->input('Socialmedia', ['type' => > 'checkbox','value' => 'Y','hiddenField' => 'N']);?> >Form->input('multilingual', ['type' => > 'checkbox','value' => 'Y','hiddenField' => 'N']);?> >Form->input('partner_incentive', ['type' => > 'checkbox','value' => 'Y','hiddenField' => 'N']);?> >Form->input('partner_app', ['type' => > 'checkbox','value' => 'Y','hiddenField' => 'N']);?> > > > Form->button(__('Save')); ?> > Form->end() ?> > > > *Controller Action* > == > public function add(){ > $package = $this->Package->newEntity($this->request->data); > if ($this->request->is('post')) { > if ($this->Package->save($package)) { > $this->Flash->success(__('The package has been saved.')); > return $this->redirect(['action' => 'index']); > } > else{ > // $errors = $this->Package->errors(); > > $error_string= implode('\n',$package->errors()); > //print_r($package); > } > $this->Flash->error(__('Unable to add the package.')); > } > $this->set('package', $package); > } > > *Model - Table Class* > = > class PackagesTable extends Table { > public function initialize(array $config) { > $this->addBehavior('Timestamp', [ > 'events' => [ > 'Model.beforeSave' => [ > 'created_on' => 'new', > 'modified_on' => 'always', > ] > > ] > ]); > } > 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; > } > } > > Regards, > Jipson > > On Wednesday, 30 July 2014 14:20:54 UTC+1, 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; >> } >>
Re: Display Form Validation Errors CakePHP 3
Hi Jose Lorenzo, Thank you very much. Now it is working perfectly. Regards, Jipson On Wednesday, 30 July 2014 14:31:30 UTC+1, José Lorenzo wrote: > > Ok, you problem is that you are calling create() without the entity, You > should get that fixed by doing: > > Form->create($package) ?> > > On Wednesday, July 30, 2014 3:29:33 PM UTC+2, Jipson Thomas wrote: >> >> Hi Jose Lorenzo, >> Thank you for the reply. Please find the below code >> >> *CTP* >> == >> >> Flash->render('auth') ?> >> Form->create() ?> >> >> > ?> >>Form->input('name', ['label' => 'Package >> Name']); ?> >>Form->input('annual_price', ['label' => 'Price / >> Year','type' => 'decimal']); ?> >>Form->input('monthly_price', ['label' => 'Price >> / Month','type' => 'decimal']); ?> >>Form->input('duration', ['label' => 'Minimum >> Months of Contract','type' => 'integer']);?> >>Form->input('no_partners', ['label' => 'Maximum >> No of Partners','type' => 'integer']);?> >>Form->input('no_emails', ['label' => 'Maximum No >> of Emails/Month','type' => 'integer']);?> >>Form->input('storage', ['label' => 'Maximum >> Allowed Storage Space (GB)','type' => 'integer']);?> >>Form->input('resource_library', ['label' => >> 'Resource Library','type' => 'checkbox','value' => 'Y','hiddenField' => >> 'N']);?> >>Form->input('portal_cms', ['label' => 'Portal >> CMS','type' => 'checkbox','value'=>'Y','hiddenField' => 'N']);?> >>Form->input('MDF', ['type' => 'checkbox','value' >> => 'Y','hiddenField' => 'N']);?> >>Form->input('deal_registration', ['type' => >> 'checkbox','value' => 'Y','hiddenField' => 'N']);?> >>Form->input('partner_recruit', ['type' => >> 'checkbox','value' => 'Y','hiddenField' => 'N']);?> >>Form->input('training', ['type' => >> 'checkbox','value' => 'Y','hiddenField' => 'N']);?> >>Form->input('Socialmedia', ['type' => >> 'checkbox','value' => 'Y','hiddenField' => 'N']);?> >>Form->input('multilingual', ['type' => >> 'checkbox','value' => 'Y','hiddenField' => 'N']);?> >>Form->input('partner_incentive', ['type' => >> 'checkbox','value' => 'Y','hiddenField' => 'N']);?> >>Form->input('partner_app', ['type' => >> 'checkbox','value' => 'Y','hiddenField' => 'N']);?> >> >> >> Form->button(__('Save')); ?> >> Form->end() ?> >> >> >> *Controller Action* >> == >> public function add(){ >> $package = $this->Package->newEntity($this->request->data); >> if ($this->request->is('post')) { >> if ($this->Package->save($package)) { >> $this->Flash->success(__('The package has been saved.')); >> return $this->redirect(['action' => 'index']); >> } >> else{ >> // $errors = $this->Package->errors(); >> >> $error_string= implode('\n',$package->errors()); >> //print_r($package); >> } >> $this->Flash->error(__('Unable to add the package.')); >> } >> $this->set('package', $package); >> } >> >> *Model - Table Class* >> = >> class PackagesTable extends Table { >> public function initialize(array $config) { >> $this->addBehavior('Timestamp', [ >> 'events' => [ >> 'Model.beforeSave' => [ >> 'created_on' => 'new', >> 'modified_on' => 'always', >> ] >> >> ] >> ]); >> } >> 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; >> } >> } >> >> Regards, >> Jipson >> >> On Wednesday, 30 July 2014 14:20:54 UTC+1, 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') >>>
Re: Display Form Validation Errors CakePHP 3
Glad it worked :) On Wednesday, July 30, 2014 3:35:21 PM UTC+2, Jipson Thomas wrote: > > Hi Jose Lorenzo, > Thank you very much. Now it is working perfectly. > Regards, > Jipson > > On Wednesday, 30 July 2014 14:31:30 UTC+1, José Lorenzo wrote: >> >> Ok, you problem is that you are calling create() without the entity, You >> should get that fixed by doing: >> >> Form->create($package) ?> >> >> On Wednesday, July 30, 2014 3:29:33 PM UTC+2, Jipson Thomas wrote: >>> >>> Hi Jose Lorenzo, >>> Thank you for the reply. Please find the below code >>> >>> *CTP* >>> == >>> >>> Flash->render('auth') ?> >>> Form->create() ?> >>> >>> >> ?> >>>Form->input('name', ['label' => 'Package >>> Name']); ?> >>>Form->input('annual_price', ['label' => 'Price >>> / Year','type' => 'decimal']); ?> >>>Form->input('monthly_price', ['label' => 'Price >>> / Month','type' => 'decimal']); ?> >>>Form->input('duration', ['label' => 'Minimum >>> Months of Contract','type' => 'integer']);?> >>>Form->input('no_partners', ['label' => 'Maximum >>> No of Partners','type' => 'integer']);?> >>>Form->input('no_emails', ['label' => 'Maximum >>> No of Emails/Month','type' => 'integer']);?> >>>Form->input('storage', ['label' => 'Maximum >>> Allowed Storage Space (GB)','type' => 'integer']);?> >>>Form->input('resource_library', ['label' => >>> 'Resource Library','type' => 'checkbox','value' => 'Y','hiddenField' => >>> 'N']);?> >>>Form->input('portal_cms', ['label' => 'Portal >>> CMS','type' => 'checkbox','value'=>'Y','hiddenField' => 'N']);?> >>>Form->input('MDF', ['type' => >>> 'checkbox','value' => 'Y','hiddenField' => 'N']);?> >>>Form->input('deal_registration', ['type' => >>> 'checkbox','value' => 'Y','hiddenField' => 'N']);?> >>>Form->input('partner_recruit', ['type' => >>> 'checkbox','value' => 'Y','hiddenField' => 'N']);?> >>>Form->input('training', ['type' => >>> 'checkbox','value' => 'Y','hiddenField' => 'N']);?> >>>Form->input('Socialmedia', ['type' => >>> 'checkbox','value' => 'Y','hiddenField' => 'N']);?> >>>Form->input('multilingual', ['type' => >>> 'checkbox','value' => 'Y','hiddenField' => 'N']);?> >>>Form->input('partner_incentive', ['type' => >>> 'checkbox','value' => 'Y','hiddenField' => 'N']);?> >>>Form->input('partner_app', ['type' => >>> 'checkbox','value' => 'Y','hiddenField' => 'N']);?> >>> >>> >>> Form->button(__('Save')); ?> >>> Form->end() ?> >>> >>> >>> *Controller Action* >>> == >>> public function add(){ >>> $package = $this->Package->newEntity($this->request->data); >>> if ($this->request->is('post')) { >>> if ($this->Package->save($package)) { >>> $this->Flash->success(__('The package has been saved.')); >>> return $this->redirect(['action' => 'index']); >>> } >>> else{ >>> // $errors = $this->Package->errors(); >>> >>> $error_string= implode('\n',$package->errors()); >>> //print_r($package); >>> } >>> $this->Flash->error(__('Unable to add the package.')); >>> } >>> $this->set('package', $package); >>> } >>> >>> *Model - Table Class* >>> = >>> class PackagesTable extends Table { >>> public function initialize(array $config) { >>> $this->addBehavior('Timestamp', [ >>> 'events' => [ >>> 'Model.beforeSave' => [ >>> 'created_on' => 'new', >>> 'modified_on' => 'always', >>> ] >>> >>> ] >>> ]); >>> } >>> 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; >>> } >>> } >>> >>> Regards, >>> Jipson >>> >>> On Wednesday, 30 July 2014 14:20:54 UTC+1, 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