Rss Feed
  1. Websites to learn!!

    Tuesday 30 October 2012

    http://www.javascriptkit.com/
     http://ntt.cc/2008/05/10/over-10-useful-javascript-regular-expression-functions-to-improve-your-web-applications-efficiency.html
    http://htmldog.com - html
    http://freeajaxscripts.net - ajax

    Javascript
    Coundown timer
    http://keith-wood.name/countdown.html

    Jquery code
    http://jsfiddle.net/tqyj4/4/       

  2. Javascript to validate all form fields when onSubmit
     
     function checkrefereremail(){
        //var testresults
        var nam=document.getElementById('name').value;
        var mob=document.getElementById('contactno').value;
        var str=document.getElementById('emailid').value;
        var anum=/(^\d+$)|(^\d+\.\d+$)/             // integer validation
      var flag=1;
        var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i     // email validation
        $('#namemsg').html('');$('#mobmsg').html('');$('#emailmsg').html('');$('#captchamsg').html('');
       if(nam == '')
       {
       document.getElementById("namemsg").innerHTML = "Please input a valid name!";
         
          flag++;
       }
       if (anum.test(mob) == false)
        {
        document.getElementById("mobmsg").innerHTML = "Please input a valid mobile no!";
        flag++;
        }
       if(filter.test(str) == false){
        document.getElementById("emailmsg").innerHTML = "Please input a valid email address!";
        flag++;
         }else
         {
            return  Captcharesult()
            return true;
         }

        }
    </script>




    Refer mydala view source:
    <script>
    function user()
    {
    var isflag=1;
    $('#emailidErr').html('');$('#cpasswordErr').html('');$('#passwordErr').html('');$('#mobilenoErr').html('');$('#dobErr').html('');$('#tcboxErr').html('');$('#captchaErr').html('');
      if($('#emailid').val()=='')
        {
            $('#emailid').addClass("red-border");
            $('#emailidErr').html('<p>Please Enter Email Id</p>');
            isflag++;
        }else{   
        var emailFilter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;    // Both work same:and are userful /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
                if(!(emailFilter.test($('#emailid').val())))
                {
                    $('#emailid').addClass("red-border");
                    $('#emailid').val('');
                    $('#emailidErr').html('<p>Please Enter Valid Email Id</p>');
                    isflag++;       
                }
        }
        if($('#password').val()=='')
        {
            $('#password').addClass("red-border");
            $('#passwordErr').html('<p>Please Enter Password</p>');
            isflag++;
        }else{   
            var Password = $('#password').val();
            if(Password.length<6)
            {
                $('#passwordErr').html('<p>Please Enter Six digit in Password</p>');
                $('#password').addClass("red-border");   
                isflag++;   
            }
            if(Password!=$('#cpassword').val())
            {
                $('#cpassword').addClass("red-border");
                $('#cpasswordErr').html('<p>Please Enter Same Password in Confirm Password</p>');
                isflag++;
            }
        }   
       
        if($('#mobileno').val()!='' )
        {
            if(!($('#mobileno').val().match(/^[0-9]+$/)))
            {
                $('#mobileno').addClass("red-border");
                $('#mobilenoErr').html('<p>Please Enter Numeric Value in Mobile Number!</p>');
                isflag++;
            }
           
            var Mobile=$('#mobileno').val();
            if ((Mobile.length<10))
            {
                $('#mobilenoErr').html('<p>Please Enter Ten digit in Mobile Number!</p>');
                $('#mobileno').addClass("red-border");
                isflag++;
            }
            if ((Mobile.length>10))
            {
                $('#mobilenoErr').html('<p>Please Enter Ten digit in Mobile Number!</p>');
                  $('#mobileno').addClass("red-border");
                  isflag++;
            }
        }
        else
        {
            $('#mobileno').addClass("red-border");
            $('#mobilenoErr').html('<p>Please Enter Your Mobile Number</p>');
            isflag++;
        }
       if($('#cityid').val()=='')
        {
            $('#cityid').addClass("red-border");
            $('#cityidErr').html('<p>Please Select City</p>');
            isflag++;
        }
        if($('#date_dd').val()=="" && $('#date_mm').val()=="" && $('#date_yy').val()=="")
            {
                    if($('#date_dd').val()==""){$('#date_dd').addClass("red-border");}
                    if($('#date_mm').val()==""){$('#date_mm').addClass("red-border");}
                    if($('#date_yy').val()==""){$('#date_yy').addClass("red-border");}
                    $('#dobErr').html('<p>Please Select Date of Birth!</p>');
                    isflag++;
            }
           
           
            if($('#b_pincode').val()!='' )
            {
                if(!($('#b_pincode').val().match(/^[0-9]+$/)))
                {
                    $('#b_pincode').addClass("red-border");
                    $('#b_pincodeErr').html('<p>Please Enter Numeric Value in Zip Code!</p>');
                    isflag++;
                }
               
                var zipcode=$('#b_pincode').val();
                if ((zipcode.length<6))
                {
                    $('#b_pincodeErr').html('<p>Please Enter six digit in Zip Code!</p>');
                    $('#b_pincode').addClass("red-border");
                    isflag++;
                }
                if ((zipcode.length>6))
                {
                    $('#b_pincodeErr').html('<p>Please Enter six digit in Zip Code!</p>');
                      $('#b_pincode').addClass("red-border");
                      isflag++;
                }
            }
           
            if($('#captcha').val()==''){
                $('#captcha').addClass("red-border");
                $('#captchaErr').html('<p>Please Enter Verification code</p>');
                isflag++;
            }
           
            if(document.form_user.tcbox.checked == false)
            {
                $('#tcbox').addClass("red-border");
                $('#tcboxErr').html('<p>Please accept the T&C.</p>');
                isflag++;
            }
           
           if(isflag > 1){
             $('#loginerror').show();
             return false;
           }
        document.getElementById('form_user').submit();
        document.form_user.submit();
    }
    </script>

  3. Scroll button click -> to open a new window
    ctrl+u ->page view source
    ctrl+home->beginning of document
    ctrl+end->end of document

  4. if (!document.feedback.field.checked) {
        // box is not checked
        return false;
    }

  5. Websites tips & tricks

    Monday 29 October 2012

    http://geteverything.org/
    http://www.brtricks.com
    http://www.woorank.com/en
    http://validator.w3.org



  6. <script>

    function checkemail(){
        //var testresults
    var str=document.getElementById('emailsub').value;
    var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    if (filter.test(str))
    {
    //testresults=true
    return  newsletter()   // this to call another javascript function
    return true;

    }
    else{
    alert("Please input a valid email address!")
    //testresults=false
    return false;
    }
    //return (testresults)
    }
    </script>


    Refer http://www.javascriptkit.com/script/script2/acheck.shtml


  7. Cakephp email!!

    Saturday 27 October 2012


     public function emailcheck()
     {
             $this->Email->smtpOptions = array(
           'port'=>'465', 
           'timeout'=>'30',
           'host' => 'ssl://smtp.gmail.com',
           'username'=>'prathapskp@gmail.com',
           'password'=>'12.06.1989',
      );
        $this->Email->delivery = 'smtp';
            $this->Email->from = 'prathap <prathapskp@yahoo.com>';
    $this->Email->to = 'prathapskp@gmail.com';
    $this->Email->subject ='hello' ;
    // $this->Email->template = 'register';
    // $this->set('user', $this->data);
                 //$this->Email->delivery = 'debug';
               if($this->Email->send('Hello message body!'))
               {
                $this->redirect('/');
                
               }else
               {
                $this->Session->setFlash(__('error occured', true));
               }

        }

    }


  8. Page reload using onclick event

    Sunday 14 October 2012

    Onclick page reload using js

     onclick="document.location.reload(true)"

  9. Simple mail sending in PHP, AJAX

    Saturday 13 October 2012

     HTML Form

    <form action="sendmail.php" method="post">
    <div style="margin:10px 0;"> Name.</div>
     <input name="username" id="username" type="text" style="width:300px; height:35px;" />         
    <span id="userspan"></span>

    <div style="margin:10px 0;">Contact No.</div>
    <input name="contact" id="contact" type="text" style="width:300px; height:35px;" />
    <span id="contactspan"></span>

    <div style="margin:10px 0;">Company Name</div>
    <input name="company" id="company" type="text" style="width:300px; height:35px;" />
    <span id="companyspan"></span>

    <div style="margin:10px 0;">Email</div>
    <input name="email" id="email" type="text" style="width:300px; height:35px;" />
    <span id="emainspan"></span>

    <div style="float:left; margin:15px 0 0 110px; padding:0;"><a onclick="return sendcontact()"><img src="img/submitbutton.png" width="82" height="28" alt="submit" /></a></div>
    </div>
    </form>



    Javascript Ajax Call

    <script type="text/javascript">

      function sendcontact()
      {
          document.getElementById('userspan').innerHTML = '';
          document.getElementById('contactspan').innerHTML = '';
          document.getElementById('companyspan').innerHTML = '';
          document.getElementById('emailspan').innerHTML = '';
         
          var name = document.getElementById("name").value;
          var comp = document.getElementById("company").value;
          var con = document.getElementById("contact").value;
          var email = document.getElementById("email").value;

          if((name == "" || name == null))
          {
              document.getElementById('name').focus();
              document.getElementById('userspan').innerHTML = 'Please Provide your Name';
              return false;
          }
         
          else if((con == "" || con == null))
          {
              document.getElementById('contact').focus();
              document.getElementById('contactspan').innerHTML = 'Please Provide your Contact No';
              return false;
          }
         
          else if((comp == "" || comp == null))
          {
              document.getElementById('company').focus();
              document.getElementById('companyspan').innerHTML = 'Please Provide your Company name';
              return false;
          }


          else if((email == "" || email == null))
          {
              document.getElementById('email').focus();
              document.getElementById('emailspan').innerHTML = 'Please Provide your Company name';
              return false;
          }
       
          if (window.XMLHttpRequest)
            {// code for IE7+, Firefox, Chrome, Opera, Safari
              xmlhttp=new XMLHttpRequest();
          }
          else
          {
              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
         
          xmlhttp.onreadystatechange=function()
          {
              if (xmlhttp.readyState==4 && xmlhttp.status==200)
              {
                  document.getElementById("contactres").innerHTML=xmlhttp.responseText;
              }
          }
         
          var str = name + '&con=' + con + '&comp=' + comp + '&email=' + email;
          xmlhttp.open("GET","sendmail.php?name="+str,true);
          xmlhttp.send();
      }
      </script>




    PHP Script

    <?php

    $name = $_GET['name'];
    $contact = $_GET['con'];
    $company = $_GET['comp'];
    $email = $_GET['email'];

    $to = 'example1@example.com, example2@example.com';
    $message = "Hi, You have got a contact from Your Web" . "\n" . "\n";
    $message .= "Name : " . $name . "\n" . "Company : " . $company . "\n" . "Contact Number : " . $contact . "\n";
    $subject = "Mail from your website";
    $from = $email;
    $headers .=  "From: ". $from;

    if(mail($to,$subject,$message,$headers))
    {
        echo "Thank you for your interest. We will get in touch with you shortly.";
    }
    else
    {
        echo "Sorry, there exist some problem. Please try again later.";
    }
    ?>

  10. To hash password in model

    Security::hash($password, 'sha1', true) ;
    AuthComponent::password($password) ;

     To check password with confirm password and to reset password

    public $validate = array(
        'name' => array(
                'notEmpty' => array(
                    'rule' => 'notEmpty',
                    'message' => 'This field cannot be left blank.',
                    'last' => true,
                ),
                'validName' => array(
                    'rule' => '_validName',
                    'message' => 'This field must be alphanumeric',
                    'last' => true,
                ),
            ),
            'username' => array(
                'isUnique' => array(
                    'rule' => 'isUnique',
                    'message' => 'The username has already been taken.',
                    'last' => true,
                ),
                'notEmpty' => array(
                    'rule' => 'notEmpty',
                    'message' => 'This field cannot be left blank.',
                    'last' => true,
                ),
                'validAlias' => array(
                    'rule' => '_validAlias',
                    'message' => 'This field must be alphanumeric',
                    'last' => true,
                ),
            ),
           
            'pwd' => array(                                                                           // password field
                'rule' => array('minLength', 6),
                'message' => 'Passwords must be at least 6 characters long.',
            ),
            'password2'  => array('rule' =>'checkpasswords','message' => 'Passwords dont match'), //confirm password field
            'oldpwd'  => array('rule' =>'checkoldnewpasswords','message' => 'Old and New Passwords dont match'), // oldpassword that to be changed
            'email' => array(
                'email' => array(
                    'rule' => 'email',
                    'message' => 'Please provide a valid email address.',
                    'last' => true,
                ),
                'isUnique' => array(
                    'rule' => 'isUnique',
                    'message' => 'Email address already in use.',
                    'last' => true,
                ),
            ),
               
           
           
        );
       

        function checkpasswords()     // to check pasword and confirm password
        {  //print_r($this->data['User']['id']);
        if(strcmp($this->data['User']['pwd'],$this->data['User']['password2']) == 0 )
        {
            return true;
        }
        return false;
        }
       
        function checkoldnewpasswords()   // to check password and old password
        {
          
            $this->id = $this->data['User']['id'];
            $user_data = $this->field('password');      
            print_r(Security::hash($this->data['User']['oldpwd'], 'sha1', true));
           if ($user_data == (Security::hash($this->data['User']['oldpwd'], 'sha1', true)))
           {
         return true;
         }else{
         return false;
         }
            }
             


    To assign password to correct database field name
    Here using   pwd i getting password in view so assigning this to database password field.

    function beforeSave() {
        parent::beforeSave();
        //print_r(($this->data['User']['newPassword']));
        //if (isset($this->data['User']['pwd']) && !empty($this->data['User']['pwd'])){
           // $this->data['User']['password'] = Security::hash($this->data['User']['pwd'], 'sha1', true);
          
            if (!empty($this->data[$this->alias]['pwd'])) {                 // hashing password with sha1 and cake salt
            $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['pwd']);
       
            }
        return true;
        }




    In view

    <?php echo $this->Form->input('oldpwd', array('type' => 'password','label' => '', 'class' => 'my-text-field-gen-11')); ?>

    <?php echo $this->Form->input('pwd', array('type' => 'password','label' => '', 'class' => 'my-text-field-gen-11')); ?>

    <?php echo $this->Form->input('password2', array('type' => 'password', 'label' => '','class' => 'my-text-field-gen-11')); ?> 


    Refer://http://www.dereuromark.de/2011/08/25/working-with-passwords-in-cakephp/


  11. Php functions

    Thursday 11 October 2012

    To delete the empty key in array

    array_filter()

    Finds whether a variable is a number or a numeric string

    is_numeric

  12. Cakephp to get base url

    <?php echo $this->webroot; ?>

    <?php $this->base ?>

  13. Java script to reload a page in Html and Cakephp

    onclick="document.location.reload(true)"

    JS onclick event in html

    <a href="#" onclick="document.location.reload(true)"></a>

    Js onClick event in cakephp

    <?php echo $this->Html->image('image.png',array('onClick' => "document.location.reload(true)"),array('escape' => false)); ?>

    Reload function in javascript

     location.reload();
     window.setTimeout('location.reload()', 3000);