Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving a JSignature 1

Status
Not open for further replies.

Marine1969

IS-IT--Management
Mar 5, 2015
60
US
I need to save a jsignature image where I found a script that works with tablets and phones to get the signature but I cannot get the save button to work. Does anyone have any suggestions? I have the code and the link to the script I found. Any help would be great. Thank you.

jsignature

PHP:
<form action="rec_maint.php">
	   <input type="hidden" name="maint" value="cssig">
	   <input type="hidden" name="rec" value="edit">
	   <input type="hidden" name="sid" value="<?php echo $_GET['sid'];?>">
	   <div id="signatureparent">
         <div id="signature"></div>
         <button type="button" onclick="$('#signature').jSignature('clear')">Clear</button>
         <button type="button" id="btnSave">Save</button>
      </div>
      <input type="hidden" id="hiddenSigData" name="hiddenSigData" />
      <div id="scrollgrabber"></div>
      <script src="jsig/src/jSignature.js"></script>
      <script src="jsig/src/plugins/jSignature.CompressorBase30.js"></script>
      <script src="jsig/src/plugins/jSignature.CompressorSVG.js"></script>
      <script src="jsig/src/plugins/jSignature.UndoButton.js"></script> 
      <script>
         $(document).ready(function() {
         var $sigdiv = $("#signature").jSignature({'UndoButton':true});

         // -- i explain from here...
         $('#btnSave').click(function(){
            var sigData = $('#signature').jSignature('getData','base30');
            $('#hiddenSigData').val(sigData);
         });
        // -- ... to here.

        })
     </script>
	  </form>
 
You are preparing your query twice.

This one is correct, you pass a string to it as it expects:

$str=$conn->prepare("Update cservice Set signature = :sig");

Then you prepare it again for some reason and pass the object resulting from the last prepare statement:

$stmt = $conn->prepare($str);


Why are doing that? The prepare method expects a string, the second time you call it you give it an object.

Try running the prepare statement only once and using the result object correctly:

Code:
[b]$str[/b]=$conn->prepare("Update cservice Set signature = :sig");
[b]$str[/b]->bindParam(':sig', $_POST['hiddenSigData'], PDO::PARAM_STR);  
[b]$str[/b]->execute();

This by the way has nothing to do with the table's column type. A Blob can accept a long text string just fine.



----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech
 
WooHoo!!! It saved! Now, I'm sure this is simple...how do I display it? I used
PHP:
echo "X<br>" . $sig . "<br>X";
and got...
X
Array
X

BTW...Thanks to everyone for helping!
 
What exactly is in $sig? Looks like you are getting an array back probably as a result form your query. Also echoing it like that, will just show a bunch of characters as explained before.

You can of course use print_r to output an array.

Code:
echo "X<br>" . [b]print_r([/b]$sig[b],1)[/b] . "<br>X";

You are going to have to create a PHP file that has the proper image headers, to display the image.



----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech
 
Does this need to be converted back to an image?

Here's my output (this is what is in the db field)...

X
Array ( [signature] => image/jsignature;base30,4B0000632567hllnrnhd895522020_4MZ88bap691000Y9hfh9500Z77bdfdb9_eGe5000Z3230Y599753232448ahllnjhd6120232027bffbb62_5EZgbohdb96Ybdd975Z556774200Y99d977Z25accdd650Y8b7220Z5 [0] => image/jsignature;base30,4B0000632567hllnrnhd895522020_4MZ88bap691000Y9hfh9500Z77bdfdb9_eGe5000Z3230Y599753232448ahllnjhd6120232027bffbb62_5EZgbohdb96Ybdd975Z556774200Y99d977Z25accdd650Y8b7220Z5 )
X
 
Not technically converted. But as you cannot display a bunch of characters as an image you will need to make PHP output proper headers so the characters are read as binary data by the browser and interpreted as an actual image.

Read here for how to do this:


----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top