Pages

Showing posts with label Set. Show all posts
Showing posts with label Set. Show all posts

Thursday, July 30, 2015

Cakephp 2.0-Validations not working

Many a times Our custom Validations do not work in cakephp due to very tiny small errors.Here is a piece of my research and development which might help you
 In the controller
       if (!empty($this->data))   
       {  
         $this->User->set($this->data);  
         if ($this->User->validates())   
         {  
           // it validated logic  
           echo "Yes we can proceed";  
         }   
         else   
         {  
           // didn't validate logic  
           $errors = $this->User->validationErrors;  
           pr($errors);  
         }  
       }  

See the line in Bold this must be done to get errors set

In the view
   <?php   
       if($this->Form->isFieldError('User.username'))  
       {  
         echo $this->Form->error('User.username', null, array('class' => 'message'));   
       }  
       ?>  
Now set the class to taste and you will get error message in view in desired color.

Wednesday, July 17, 2013

Web Development/Jquery/Javascript-Set a menu Link "selected" class if its href matches page url

Here is a simple js code with HTML to set a "seected" class to menu item when its corresponding page is open.

 <dl class="sidebarBox">  
   <dt>Mailboxes</dt>  
   <dd>  
     <ul class="mailbar">  
       <li><a href="inbox"><b>Inbox</b></a></li>  
       <li><a href="sent">Sent</a></li>  
       <li><a href="trash">Trash</a></li>  
     </ul>  
   </dd>  
 </dl>  
 <script type="text/javascript">  
   var winpath=window.location.pathname;  
   $(".mailbar li a").each(function(index)  
   {  
     var menupath=$(this).attr('href');  
     if(menupath==winpath)  
       $(this).parent().addClass("current");  
     else  
       $(this).parent().removeClass("current");  
   });  
 </script>