Skip to main content

Get Google Calendar Event List in WordPress

<a href="https://console.cloud.google.com/apis/credentials">Get Your Api Credentials Here</a> <a href="https://calendar.google.com/calendar">Get your Calender ID</a> <?php include_once("wp-load.php"); function  get_calender_events() { $params = array(); /*Get current date*/ $current_date  = date('Y-m-d H:i:s'); /*Convert it to google calendar's rfc_format */ $rfc_format = date("c", strtotime($current_date)); $params[] = 'orderBy=startTime'; $params[] ='maxResults=100'; $params[] = 'timeMin='.urlencode($rfc_format); $url_param = ''; foreach($params as $param) { $url_param.= '&'.$param; } $calender_id = "calender_id"; $client_key =  "client_key"; $url = "https://www.googleapis.com/calendar/v3/calendars/".$calender_id."/events?key=".$client_key."&singleEvents=true".$url_param; $list_events = wp_remote_post($url,

Create Signature pad with save on database in php

Create Signature pad with save on database in php

1.create a folder images


index.php
============
  <!DOCTYPE >

    <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <title>Signature Pad</title>
    <script type="text/javascript" src="jquery-1.8.0.min.js"></script>
    <script type="text/javascript">

$(document).ready(function () {
    /** Set Canvas Size **/
    var canvasWidth = 400;
    var canvasHeight = 100;

    /** IE SUPPORT **/
    var canvasDiv = document.getElementById('signaturePad');
    canvas = document.createElement('canvas');
    canvas.setAttribute('width', canvasWidth);
    canvas.setAttribute('height', canvasHeight);
    canvas.setAttribute('id', 'canvas');
    canvasDiv.appendChild(canvas);
    if (typeof G_vmlCanvasManager != 'undefined') {
        canvas = G_vmlCanvasManager.initElement(canvas);
    }
    context = canvas.getContext("2d");

    var clickX = new Array();
    var clickY = new Array();
    var clickDrag = new Array();
    var paint;

    /** Redraw the Canvas **/
    function redraw() {
        canvas.width = canvas.width; // Clears the canvas

        context.strokeStyle = "#000000";
        context.lineJoin = "miter";
        context.lineWidth = 2;

        for (var i = 0; i < clickX.length; i++) {
            context.beginPath();
            if (clickDrag[i] && i) {
                context.moveTo(clickX[i - 1], clickY[i - 1]);
            } else {
                context.moveTo(clickX[i] - 1, clickY[i]);
            }
            context.lineTo(clickX[i], clickY[i]);
            context.closePath();
            context.stroke();
        }
    }

    /** Save Canvas **/
    $("#saveSig").click(function saveSig() {
        var sigData = canvas.toDataURL("image/png");
        $("#imgData").html('Thank you! Your signature was saved');
        var ajax = XMLHttpRequest();
        ajax.open("POST", 'post-html.php');
        ajax.setRequestHeader('Content-Type', 'application/upload');
        ajax.send(sigData);
    });

    /** Clear Canvas **/
$("#clearSig").click(function clearSig() {
 
        clickX = new Array();
        clickY = new Array();
        clickDrag = new Array();
        canvas.width = canvas.width;
        canvas.height = canvas.height;
  });
    /**Draw when moving over Canvas **/
    $('#signaturePad').mousemove(function (e) {
        if (paint) {
            addClick(e.pageX - this.offsetLeft, e.pageY - this.offsetTop, true);
            redraw();
        }
    });

    /**Stop Drawing on Mouseup **/
    $('#signaturePad').mouseup(function (e) {
        paint = false;
    });

    /** Starting a Click **/
    function addClick(x, y, dragging) {
        clickX.push(x);
        clickY.push(y);
        clickDrag.push(dragging);
    }

    $('#signaturePad').mousedown(function (e) {
        var mouseX = e.pageX - this.offsetLeft;
        var mouseY = e.pageY - this.offsetTop;

        paint = true;
        addClick(e.pageX - this.offsetLeft, e.pageY - this.offsetTop);
        redraw();
    });

});
</script>
    </head>
    <body>
    <center>
        <fieldset style="width: 435px">
            <br/>
            <br/>
            <div id="signaturePad" style="border: 1px solid #00C; height: 100px; width: 400px;"></div>
            <br/>
            <button  id="clearSig" type="button">Clear Signature</button>&nbsp;
            <button id="saveSig" type="button">Save Signature</button>
            <div id="imgData"></div>
            <div id="imgData"></div>
            <br/>
            <br/>
        </fieldset>
    </center>
    </body>
    </html>


2.post-html.php
==================

 <?php
if (isset($GLOBALS["HTTP_RAW_POST_DATA"]))
{
$session_id = $_SERVER['REMOTE_ADDR'];
// Get the data
$imageData=$GLOBALS['HTTP_RAW_POST_DATA'];

// Remove the headers (data:,) part.
// A real application should use them according to needs such as to check image type
$filteredData=substr($imageData, strpos($imageData, ",")+1);

// Need to decode before saving since the data we received is already base64 encoded
$unencodedData=base64_decode($filteredData);

//echo "unencodedData".$unencodedData;
$imageName = "sign_" . rand(5,1000) . rand(1, 10) . rand(10000, 150000) . rand(1500, 100000000) . ".png";
//Set the absolute path to your folder (i.e. /usr/home/your-domain/your-folder/
$filepath = "images/" . $imageName;

$fp = fopen("$filepath", 'wb' );
fwrite( $fp, $unencodedData);
fclose( $fp );

//Connect to a mySQL database and store the user's information so you can link to it later
$link = mysql_connect('localhost','root', '') OR DIE(mysql_error);
mysql_select_db("test", $link);
mysql_query("INSERT INTO customer (`session`, `image_location`) VALUES ('$session_id', '$imageName')") OR DIE(mysql_error());
mysql_close($link);
}
?>

Comments

  1. hi
    this code is not working ..

    ReplyDelete
    Replies
    1. Hello Narendra,


      You need to add jQuery library first in heade then it's working .

      see online url
      http://code.jquery.com/jquery-latest.min.js

      Delete
  2. Thank You
    this code is working but insertion to db problem

    ReplyDelete
    Replies
    1. hello,
      You need to create db and table and all field related to that query in MySQL .

      Delete
  3. Hi,

    I am trying your code but here is not working! I follow all instruction like integrate latest jquery, create db and table but no signature save on images folder and db.

    Any help?

    ReplyDelete
  4. I can fix it. Just apply to jquery ajax method.

    your code simply awesome.

    Thanks a lot.

    ReplyDelete
    Replies
    1. this code is not working can u give me the correct code. plzzzz

      Delete
    2. how can i fix this code... plz helpppp

      Delete
  5. this code is not working. can anyone help meeee plzzzzzz :/ :/ :/

    ReplyDelete
  6. it works :) . including another library

    ReplyDelete
    Replies
    1. What library did you use? Did this solve mobile issue?

      Delete
    2. What library did you use? Did this solve mobile issue?

      Delete
  7. nice code, just need to change 2 lines of code and it will work. thanks samrat

    ReplyDelete
  8. This doesnt work on my mobile or my tablet. Any solution to this

    ReplyDelete
  9. Nice code..Working Properly

    ReplyDelete
  10. can u help me? front end is okay but in backend data is not entering neither image is being saved, help me please

    ReplyDelete
  11. what that two code line to be changed

    ReplyDelete
  12. this is working but on a ssl site drawing is below the mouse pointer

    ReplyDelete
  13. this code are jquery stupid depends.. that the reason so problematic

    ReplyDelete
  14. jquery cant working, any help for me ?

    ReplyDelete
  15. It is not working in mobile

    ReplyDelete
  16. It is not working in mobile.Please help me...

    ReplyDelete
  17. does anyone has the working code? i would appreciate the information

    ReplyDelete
  18. Code is not being saved to my folder or to the database. I have set the direct path to my folder and I have created the database/table/columns. Still not working. Please help

    ReplyDelete
    Replies
    1. i also try many ways but still not work every one who work this code please attach to me !!!

      Delete
  19. I can look at this code and tell it don't work. Yall don't even try wasting your time

    ReplyDelete
  20. Code Change:

    /** Save Canvas **/
    $("#saveSig").click(function saveSig() {
    var sigData = canvas.toDataURL("image/png");
    $("#imgData").html('Thank you! Your signature was saved');
    var ajax = new XMLHttpRequest();
    ajax.open("POST", 'post-html.php');
    ajax.setRequestHeader('Content-Type', 'application/upload');
    ajax.send(sigData);
    });



    Need create MySQL database:

    --------------------
    CREATE TABLE IF NOT EXISTS `customer` (
    `session` int(11) NOT NULL,
    `image_location` varchar(200) COLLATE utf8_bin NOT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

    ReplyDelete

Post a Comment

Popular posts from this blog

Create post with all post type

<?php /* add_action( 'wp_enqueue_scripts', 'mpcth_child_enqueue_scripts', 1000 ); function mpcth_child_enqueue_scripts() { wp_enqueue_style( 'mpc-styles-child', get_stylesheet_directory_uri() . '/style_custom.css' ); } */ function registration_form( $username, $fname, $lname, $email, $password, $confirm_password, $account_type, $distict_city, $school_name ,$school_address, $school_type, $grade_level, $invcode ) { ?>     <style>       /* Always set the map height explicitly to define the size of the div        * element that contains the map. */     #map {     height: 260px; }     </style>   <script> function initMap() {     var map = new google.maps.Map(document.getElementById('map'), {       center: {lat: -33.8688, lng: 151.2195},       zoom: 13     });     var input = document.getElementById('searchInput');    // map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);    

WooCommerce Mini cart With Ajax

WooCommerce Mini cart //MINI CART SECTION   <div class="productdiv rightcart">                                                         <?php if ( ! WC()->cart->is_empty() ) : ?>     <ul class="woocommerce-mini-cart cart_list product_list_widget <?php echo esc_attr( $args['list_class'] ); ?>">         <?php             do_action( 'woocommerce_before_mini_cart_contents' );             foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {                 $_product     = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );                 $product_id   = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );                 if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_widget_c