Rss Feed
  1. Jquery function passing parameters!!

    Wednesday 28 November 2012




    php echo $row['id']; ?>">Edit User
    $('a.edit').click(function () {
        var id = $(this).data('id');
        // do something with the id
        return false;
    });

  2. JQuery website for ajax content, pagination, email check, and more....


    http://www.mix26.com/

  3. JQuery Auto complete plugin


    http://jqueryui.com/autocomplete/

    Html->script('jquery-ui'); ?>
    Html->css('jquery-ui'); ?>  

       

       
     


    Html form

    Form->input('place',array('label' => '','id' => 'LocationmasterName', 'title' => 'Local search...'));  ?>



  4. Note: Ignore all comments

    SCRIPT

    <script type="text/javascript">var myBaseUrl = '<?php echo $this->base; ?>';</script> // finds the base URL
    <script type="text/javascript">
    $(document).ready(function(){
       
        $('#DealTypemasterId').change(function(){ // when dropdown value gets changed function executes
        $.ajax({
            type : "POST",
                    url  : myBaseUrl + ('/deals/populateSubcat') + '?q=' + $("#DealTypemasterId option:selected").val(), //pass query string to server
                    success : function(opt){
                            document.getElementById('DealSubcatId').innerHTML = opt;   // assign the output to another dropdown
                        }
                })
                });
                });
           
    </script>


    HTML


    <?php echo $this->Form->create('Deal');?>
    <?php echo $this->Form->input('typemaster_id', $typemasters);?>
    <?php echo $this->Form->input('subcat_id', $subcats);?>
    <?php echo $this->Form->input('merchantmaster_id', $merchantmasters);?><br />
    <?php echo $this->Form->end(__('Submit', true));?>


    PHP

    Controller:
    //fetch all data from database

        function populateSubcat()
        {
           
        $location = $this->Subcat->find('list', array('fields' => array('name')));
    $this->set('locations', $location);
    $this->layout = 'ajax';

        }  


    View:
    //print the values set in controller in the format of javascript array, which is needed for autocomplete jquery. 
    <?php 
    $locat = implode(',', $locations);
    echo $locat;
    ?>




  5. Jquery functions for event



    $(document).ready(function(){
    $("#yourid").focusout(function() {

    alert('coding here');

    });
    });

  6. $('#yourElementId').attr('title', 'your new title');
    var assign = $('#yourElementId').attr('title');

  7. Paasing parameter and submitting image using form

     <?php echo $this->Form->create('Deal', array('url' => array($mid,$mname),'type' => 'file'));?>

  8. To test like button in website

    https://developers.facebook.com/tools/debug

    Multiple like button in a page

    http://hillarsaare.com/multiple-facebook-like-buttons-on-one-page/

    Meta tag for like button

    http://blog.smartwebsitetips.com/75/how-to-force-facebook-choose-right-image-for-like-button/

  9. Php date difference!!

    Thursday 8 November 2012

    Php date difference between sql date and current date:

    <?php $curtime = date("Y-m-d H:i:s"); // Mysql date format
          $endtime = $sd['denddate'];
         $ts1 = strtotime($curtime);
        $ts2 = strtotime($endtime);
         $diff = ($ts2 - $ts1)/3600/24;
        echo round($diff);  ?>

  10. Php email validation!!

    Tuesday 6 November 2012

    <?php
    $email_a = 'joe@example.com';
    if (filter_var($email_a, FILTER_VALIDATE_EMAIL)) {
        echo "This (email_a) email address is considered valid.";
    }

    ?>



    Using regular expression

    <?php
    ereg("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]",
         $email);
    ?>

  11. Php to generate random numbers!!

    Thursday 1 November 2012



    Random string generation

      function generateRandomString($length = 10) { // to generate rendom strings
        $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $randomString = '';
        for ($i = 0; $i < $length; $i++) {
            $randomString .= $characters[rand(0, strlen($characters) - 1)];
        }
        return $randomString;
        //refer :http://stackoverflow.com/questions/4356289/php-random-string-generator
    }