I am using the jQuery Signare Pad found here, with the source and demo: http://www.jqueryscript.net/mobile/Simpe-Mobile-Signature-Pad-with-jQuery-Html5-Canvas.html
Right now all it does is show the image of your signature when you click done. So it now with the image on the page, how can I get this to go over when I submit my form.
I am submitting my form to a PDF converter called mPDF using a modified version of this: http://mpdf1.com/manual/index.php?tid=373
What I would want now is to get it from that image on the page to be an image on the PDF, as when you click submit it does not know to pull that image over.
I am not the most savvy in PHP as I'm learning as I go, any help would be greatly appreciated.
Updated code provided by Thanasis Grammatopoulos
function fun_submit() {
if(isSign) {
var canvas = $("#canvas").get(0);
var imgData = canvas.toDataURL();
//Here the code change, do not display image, sent it to the server
$.ajax({
type: "POST",
url: "script.php",
data: {
imgBase64: imgData
}
}).done(function(o){
alert('Submited.');
});
closePopUp();
} else {
alert('Please sign');
}
}
PHP:
<?php
define('UPLOAD_DIR', 'up/');
$img = $_POST['imgData'];
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = UPLOAD_DIR . uniqid() . '.png';
$success = file_put_contents($file, $data);
?>
Still only provides a 0kb .png file on the server with nothing in it. Where do I go from here?