php - Email Validaion are not Working in Cakephp 3.0 -


email validation not working , if take name of field email take email not perfect validation 'a@a' working if take email otherwise non-empty working only.

recommendtable.php

 <?php     namespace app\model\table;      use app\model\entity\recommend;     use cake\orm\query;     use cake\orm\ruleschecker;     use cake\validation\validator;      class recommendtable extends table     {          public function initialize(array $config)         {              parent::initialize($config);              $this->table('recommend');             $this->displayfield('id');             $this->primarykey('id');             $this->addbehavior('timestamp');         }         public function validationdefault(validator $validator)         {             $validator = new validator();                  $validator     ->requirepresence('name')     ->notempty('name', 'please fill field')     ->add('name', [     'length' => [     'rule' => ['minlength', 10],     'message' => 'titles need @ least 10 characters long',     ]     ]);      $validator->add("emai", "validformat", [         "rule" => ["email"],         "message" => "email must valid."     ]);                  $validator     ->requirepresence('yemail')     ->notempty('yemail', 'please fill field..')     ->add('yemail', ['length' => ['rule' => ['minlength', 10],'message' => 'titles need @ least 10 characters long',]]);      return $validator;         }         public function buildrules(ruleschecker $rules)         {             $rules->add($rules->isunique(['email']));             return $rules;         }     } 

recommend.php

<?php namespace app\model\entity;  use cake\auth\defaultpasswordhasher; use cake\orm\entity;   class recommend extends entity {      protected $_accessible = [         '*' => true,         'id' => false,     ];      protected function _setpassword($value)     {         $hasher = new defaultpasswordhasher();         return $hasher->hash($value);     } } 

index.ctp

 <?= $this->form->create($temp) ?>                 <div class="row">                 <div class="container">                     <div class="comment-form">                         <div class="row">                             <div>                                 <h2>                                 <center>                                recommend friends/library                                  </center>                                 </h2>                             </div><fieldset>                            <div class="col-md-12 col-sm-12">                                 <div class="input-container">                                     <?php                                     echo $this->form->input('emai',array('id'=>'emai','label'=>'to ( receiver’s mail-id)',"placeholder"=>"send e-mail multiple (seperated commas).")) ?>                                 </div>                             </div>                             <div class="col-md-6 col-sm-3">                                 <div class="input-container">                                     <?php                                     echo $this->form->input('name',array('id'=>'name','label'=>'name',"placeholder"=>"name")); ?>                                 </div>                             </div>                             <div class="col-md-6 col-sm-3">                                 <div class="input-container">                                     <?php                                     echo $this->form->input('yemail',array('id'=>'yemail','label'=>'from',"placeholder"=>"from")); ?>                                 </div>                             </div>                             <div class="col-md-12 col-sm-12">                                 <div class="input-container">                                    <label>message</label>                                     <textarea name="msg" id="msg" style="resize: none;text-align:justify; " disabled placeholder="hello"></textarea>                                 </div>                             </div>      </fieldset>     <div class="col-md-12 col-sm-12">     <div class="input-container">     <?= $this->form->button(__('submit')) ?>      <button type="reset">reset</button>     <?= $this->form->end() ?></div> 

recommend controller

<?php namespace app\controller; use cake\orm\tableregistry; use app\controller\appcontroller; use cake\mailer\email;  use cake\orm\table; use app\model\tabel\recommendtabel;  use cake\event\event; class recommendcontroller extends appcontroller  {  public function index()     {          $temp = $this->recommend->newentity();         if ($this->request->is('post')) {             $temp = $this->recommend->patchentity($temp, $this->request->data);             if($temp) {                 $name=$this->request->data('name');         $receiver_email=$this->request->data('emai');          $subject_title='temp';         $sender_email=$this->request->data('yemail');          $email = new email();         $email->template('invite', 'default')             ->viewvars(['value' => $name])             ->emailformat('html')             ->from($sender_email)             ->to($receiver_email)             ->subject($subject_title)             ->send();                 $this->flash->success(__('the user has been saved.'));                 return $this->redirect(['action' => 'add']);             } else {                 $this->flash->error(__('the user not saved. please, try again.'));             }         }         $this->set(compact('temp'));         $this->set('_serialize', ['temp']);      } 

the patchentity function returns patched entity. so, result of line evaluate true when used in boolean context.

$temp = $this->recommend->patchentity($temp, $this->request->data); 

so, check whether errors detected, if statement cannot compare returned value true, instead this:

if (!$temp->errors()) { 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -