I am trying to recreate a signature in a canvas when the page loads.
I have managed to capture a signature and store it in a MySQL database using PHP. It is stored as json data.
Now the problem is this:
I have a page with a canvas element and I can retrieve the json data from the database before the page loads using php but I do not know how to pass this data to the canvas element.
Hoping for a solution because I have spent too many hours messing this up.
Thank you!
json data:
"[
{
\"lx\":87,
\"ly\":6,
\"mx\":87,
\"my\":5
},
{
\"lx\":88,
\"ly\":5,
\"mx\":87,
\"my\":6
},
{
\"lx\":89,
\"ly\":6,
\"mx\":88,
\"my\":5
},
{
\"lx\":89,
\"ly\":7,
\"mx\":89,
\"my\":6
},
{
\"lx\":90,
\"ly\":7,
\"mx\":89,
\"my\":7
},
{
\"lx\":90,
\"ly\":8,
\"mx\":90,
\"my\":7
},
{
\"lx\":90,
\"ly\":10,
\"mx\":90,
\"my\":8
},
{
\"lx\":91,
\"ly\":11,
\"mx\":90,
\"my\":10
},
{
\"lx\":92,
\"ly\":11,
\"mx\":91,
\"my\":11
},
{
\"lx\":92,
\"ly\":12,
\"mx\":92,
\"my\":11
},
{
\"lx\":93,
\"ly\":12,
\"mx\":92,
\"my\":12
},
{
\"lx\":93,
\"ly\":13,
\"mx\":93,
\"my\":12
},
{
\"lx\":95,
\"ly\":15,
\"mx\":93,
\"my\":13
},
{
\"lx\":96,
\"ly\":16,
\"mx\":95,
\"my\":15
},
{
\"lx\":97,
\"ly\":16,
\"mx\":96,
\"my\":16
},
{
\"lx\":97,
\"ly\":17,
\"mx\":97,
\"my\":16
},
{
\"lx\":98,
\"ly\":18,
\"mx\":97,
\"my\":17
},
{
\"lx\":99,
\"ly\":18,
\"mx\":98,
\"my\":18
},
{
\"lx\":99,
\"ly\":19,
\"mx\":99,
\"my\":18
},
{
\"lx\":99,
\"ly\":20,
\"mx\":99,
\"my\":19
},
{
\"lx\":102,
\"ly\":5,
\"mx\":102,
\"my\":4
},
{
\"lx\":101,
\"ly\":5,
\"mx\":102,
\"my\":5
},
{
\"lx\":101,
\"ly\":6,
\"mx\":101,
\"my\":5
},
{
\"lx\":100,
\"ly\":7,
\"mx\":101,
\"my\":6
},
{
\"lx\":100,
\"ly\":8,
\"mx\":100,
\"my\":7
},
{
\"lx\":99,
\"ly\":8,
\"mx\":100,
\"my\":8
},
{
\"lx\":99,
\"ly\":9,
\"mx\":99,
\"my\":8
},
{
\"lx\":98,
\"ly\":9,
\"mx\":99,
\"my\":9
},
{
\"lx\":98,
\"ly\":10,
\"mx\":98,
\"my\":9
},
{
\"lx\":97,
\"ly\":11,
\"mx\":98,
\"my\":10
},
{
\"lx\":96,
\"ly\":12,
\"mx\":97,
\"my\":11
},
{
\"lx\":95,
\"ly\":12,
\"mx\":96,
\"my\":12
},
{
\"lx\":94,
\"ly\":12,
\"mx\":95,
\"my\":12
},
{
\"lx\":93,
\"ly\":12,
\"mx\":94,
\"my\":12
},
{
\"lx\":91,
\"ly\":13,
\"mx\":93,
\"my\":12
},
{
\"lx\":89,
\"ly\":14,
\"mx\":91,
\"my\":13
},
{
\"lx\":89,
\"ly\":15,
\"mx\":89,
\"my\":14
},
{
\"lx\":88,
\"ly\":15,
\"mx\":89,
\"my\":15
},
{
\"lx\":87,
\"ly\":16,
\"mx\":88,
\"my\":15
},
{
\"lx\":86,
\"ly\":17,
\"mx\":87,
\"my\":16
},
{
\"lx\":86,
\"ly\":18,
\"mx\":86,
\"my\":17
},
{
\"lx\":85,
\"ly\":18,
\"mx\":86,
\"my\":18
},
{
\"lx\":85,
\"ly\":19,
\"mx\":85,
\"my\":18
},
{
\"lx\":85,
\"ly\":20,
\"mx\":85,
\"my\":19
},
{
\"lx\":84,
\"ly\":20,
\"mx\":85,
\"my\":20
}
]"
You have 2 options:
Echo into a javascript variable when you generate the page:
echo "<script>var sig = ".$jsonsig.";</script>";
or retrieve it after the page has loaded with an AJAX call
(jQuery in your page script, requires a PHP script to return the JSON code)
$.getJSON("getmysig.php",function(data) {
// create canvas here
});
Related
I have a problem with getting some values from Woocommerce $item object.
I'm trying to extract data from "meta_data" -> "_advanced_woo_discount_item_total_discount" -> initial_price, discounted_price and "discount_value" from "total _discount_details".
I tried with $item->get_meta_data(); but got a blank return.
{
"id":55,
"order_id":11501,
"name":"test",
"product_id":6419,
"variation_id":6421,
"quantity":1,
"tax_class":"",
"subtotal":"182.491803",
"subtotal_tax":"40.15",
"total":"182.491803",
"total_tax":"40.15",
"taxes":{
"total":{"1":"40.148197"},
"subtotal":{"1":"40.148197"}
},
"meta_data":[{
"id":457,
"key":"pa_velikost",
"value":"180cm"
},
{
"id":458,
"key":"_advanced_woo_discount_item_total_discount",
"value":
{
"initial_price":278.3,
"discounted_price":222.64000000000001,
"total_discount_details":
{
"8e39099d383d7d50a8c4fce98e59cc79":
{
"1":
{
"set_discount":0,
"bulk_discount":0,
"simple_discount":
{
"discount_type":"percentage",
"discount_value":"20",
"discount_quantity":1,
"discount_price_per_quantity":55.660000000000004,
"discount_price":55.660000000000004
}
}
}
},
"cart_discount_details":[],
"apply_as_cart_rule":["no"],
"discount_lines":
{
"non_applied":{
"quantity":0,
"discount":0,
"price":278.3,
"calculate_discount_from":278.3
},
"0":
{
"quantity":1,
"discount":55.660000000000004,
"original_price":278.3,
"discounted_price":222.64000000000001
}
},
"cart_quantity":1,
"product_id":6421,
"initial_price_based_on_tax_settings":278.3,
"discounted_price_based_on_tax_settings":222.64000000000001
}
}
]
}
Try with get_meta()
Example:
$item->get_meta('_advanced_woo_discount_item_total_discount')
I am having problems while trying to show info from a Json to an alert, this is my code.
function check_values_chbx(){
var pre_insc = [];
}).done(function(response){
for(i=0; i<response.length; i++){
pre_insc[i] = response[0]['personas'][i]['name']+" "+response[0]['personas'][i]['ap_pat']+" "+response[0]['personas'][i]['ap_mat'];
}
alert(pre_insc[1]);
swal({
title: "Detalles de inscripcion",
text: "Participantes que quedaran inscritos: \n\n"+pre_insc.join('\n')+"\n\nCategoria:",
buttons: true,
dangerMode: false,
}).then((willDelete) => {
if (willDelete) {
swal("Participantes registrados con exito, mucha suerte!", {
icon: "success",
});
}else {
location.reload();
}
});
});
}
And this is my JSON
[
{
"personas": [
{
"name": "Jessica",
"ap_pat": "BocaNegra",
"ap_mat": "Garcia"
},
{
"name": "Fernando",
"ap_pat": "Soto",
"ap_mat": "Olivas"
}
],
"evento": [
{
"name": "Carrera larga"
}
],
"categoria": [
{
"name": "Juvenil"
}
]
}
]
I need to print each name like:
swal("name1\n"+name2\n"+etc").
Please if someone could help me it will be very helpful, have a nice day.
You can use the below script which recursively iterates a json object if it finds an array or Object until it finds the text for the given property and then print them all if the property name is name with \n separator, you can add the following inside your script file and pass it the response that you are receiving and use the returned names with your sweetAlert, just make sure you pass the response to the function like below
names = jsonParser.getNames(response[0]);
Add the below in you script
var jsonParser = {
isObject: function (property) {
return property && {}.toString.call(property) === '[object Object]';
},
isArray: function (property) {
return property && {}.toString.call(property) === '[object Array]';
},
getNames: function (errors) {
var data = "";
for (let message in errors) {
var errorSet = errors;
if (errorSet.hasOwnProperty(message)) {
if (jsonParser.isArray(errorSet[message]) || jsonParser.isObject(
errorSet[message])) {
data += jsonParser.getNames(errors[message]);
} else if (message == 'name') {
data += errorSet[message] + "\n";
}
}
}
return data;
}
};
An example to read the names from your given response is given below.
var jsonParser = {
isObject: function(property) {
return property && {}.toString.call(property) === '[object Object]';
},
isArray: function(property) {
return property && {}.toString.call(property) === '[object Array]';
},
convertToString: function(errors) {
var data = "";
for (let message in errors) {
var errorSet = errors;
if (errorSet.hasOwnProperty(message)) {
if (jsonParser.isArray(errorSet[message]) || jsonParser.isObject(
errorSet[message])) {
data += jsonParser.convertToString(errors[message]);
} else if (message == 'name') {
data += errorSet[message] + "\n";
}
}
}
return data;
}
};
var response = [{
"personas": [{
"name": "Jessica",
"ap_pat": "BocaNegra",
"ap_mat": "Garcia"
},
{
"name": "Fernando",
"ap_pat": "Soto",
"ap_mat": "Olivas"
}
],
"evento": [{
"name": "Carrera larga"
}],
"categoria": [{
"name": "Juvenil"
}]
}];
var names = '';
names = jsonParser.convertToString(response[0]);
console.log(names);
Your final script should look like
function check_values_chbx(){
var pre_insc = [];
}).done(function (response) {
var names = jsonParser.getNames(response[0]);
swal({
title: "Detalles de inscripcion",
text: "Participantes que quedaran inscritos: \n\n" + names +
"\n\nCategoria:",
buttons: true,
dangerMode: false,
}).then((willDelete) => {
if (willDelete) {
swal("Participantes registrados con exito, mucha suerte!", {
icon: "success",
});
} else {
location.reload();
}
});
});
Hope this helps you out
I have installed FPDF in my project, and want to generate a PDF file that contains data in a table format. I want to send JSON formatted data to FPDF. How to do this?
My JSON data is this:
{
"data": [
{
"ttfdgdf": "Input1"
},
{
"number": "12"
},
{
"gfgfgrg": "Sagar"
},
{
"bfghngfh": "12323445"
},
{
"mvbmnbm": "Hi this is sagar coming from satara\t\t\t\t"
},
{
"1425278796425303": "on"
},
{
"1425278796425605": "on"
},
{
"lkl": "Hiiii"
},
{
"lklkl": "1:12 AM"
}
]
}
I am having problems prefilling textTabs for my server templates in my docusign console. My application generates an agreement on our end and is added as a composite template along with another form that is added as a server template with a template id.
The server template has several fields the user needs to be able to fill out. The tabs have been defined and added with the manage template tool in the docusign console.
I have no problems sending the documents and the signHereTab is the only one that is correctly added to the form.
The two problems I have are 1) the fields the user should fill out are never shown on the recieved document, 2) the prefill information I am sending is not received by docusign. Below is the body request I am sending to the docusign REST API:
{
"emailSubject":"Nexogy Service Agreement Signature Request",
"emailBlurb":"Thank you for your interest in our services. Please sign the following agreement to continue with your service installation.",
"status":"sent",
"emailSettings":{
"replyEmailAddressOverride":"sales#nexogy.com",
"replyEmailNameOverride":"Nexogy",
"bccEmailAddresses":[
]
},
"eventNotification":{
"url":"https:\/\/dna.local.com\/documents\/set-status",
"loggingEnabled":true,
"requireAcknowledgment":true,
"useSoapInterface":false,
"includeDocuments":false,
"includeSenderAccountAsCustomField":true,
"envelopeEvents":[
{
"envelopeEventStatusCode":"Sent"
},
{
"envelopeEventStatusCode":"Delivered"
},
{
"envelopeEventStatusCode":"Signed"
},
{
"envelopeEventStatusCode":"Voided"
},
{
"envelopeEventStatusCode":"Declinded",
"includeDocuments":true
},
{
"envelopeEventStatusCode":"Completed",
"includeDocuments":true
}
]
},
"recipients":{
"signers":[
{
"email":"mmoreno509#gmail.com",
"name":"Test Tester",
"roleName":"Signer1",
"recipientId":718
}
]
},
"compositeTemplates":[
{
"inlineTemplates":[
{
"sequence":1,
"recipients":{
"signers":[
{
"email":"mmoreno509#gmail.com",
"name":"Test Tester",
"roleName":"Signer1",
"recipientId":718,
"tabs":{
"signHereTabs":[
{
"xPosition":100,
"yPosition":205,
"documentId":1,
"pageNumber":6,
"fontColor":"BrightBlue"
}
]
}
}
]
},
"documents":[
{
"documentId":1,
"name":"ChuyMPDFAgreement.pdf",
"remoteUrl":"https:\/\/s3.amazonaws.com\/dna_local\/ChuyMPDFAgreement.pdf"
}
]
}
]
},
{
"serverTemplates":[
{
"sequence":2,
"templateId":"ae435358-1410-40fd-803e-273028d19287",
"recipients":{
"signers":[
{
"email":"mmoreno509#gmail.com",
"name":"Test Tester",
"roleName":"Signer1",
"recipientId":718,
"tabs":{
"textTabs":[
{
"tabLabel":"Full Name",
"value":"Test Tester",
"pageNumber":"1"
},
{
"tabLabel":123123123,
"value":123123123,
"pageNumber":"1"
},
{
"tabLabel":"Address",
"value":"Test",
"pageNumber":"1"
},
{
"tabLabel":"City",
"value":"Hollywood",
"pageNumber":"1"
},
{
"tabLabel":"State",
"value":"FL",
"pageNumber":"1"
},
{
"tabLabel":"ZipCode",
"value":33081,
"pageNumber":"1"
},
{
"tabLabel":"Country",
"value":"US",
"pageNumber":"1"
},
{
"tabLabel":"Phone",
"value":"3454657676",
"pageNumber":"1"
},
{
"tabLabel":"AccountName",
"value":"Testing Company",
"pageNumber":"1"
},
{
"tabLabel":"\\*FullName",
"value":"Test Tester",
"pageNumber":"1"
}
]
}
}
]
}
}
]
},
{
"serverTemplates":[
{
"sequence":3,
"templateId":"017d0d20-754b-4093-8896-ff1c00ee2cda",
"recipients":{
"signers":[
{
"email":"mmoreno509#gmail.com",
"name":"Test Tester",
"roleName":"Signer1",
"recipientId":718,
"tabs":{
"textTabs":[
{
"tabLabel":"AccountName",
"value":"Testing Company",
"pageNumber":"1"
},
{
"tabLabel":123123123,
"value":123123123,
"pageNumber":"2"
}
]
}
}
]
}
}
]
},
{
"serverTemplates":[
{
"sequence":4,
"templateId":"11a88684-07ac-4ee5-9994-cb88635fb42f",
"recipients":{
"signers":[
{
"email":"mmoreno509#gmail.com",
"name":"Test Tester",
"roleName":"Signer1",
"recipientId":718,
"tabs":{
"textTabs":[
{
"tabLabel":"AccountName",
"value":"Testing Company",
"pageNumber":"2"
},
{
"tabLabel":"Address",
"value":"Test",
"pageNumber":"1"
},
{
"tabLabel":"City",
"value":"Hollywood",
"pageNumber":"1"
},
{
"tabLabel":"State",
"value":"FL",
"pageNumber":"1"
},
{
"tabLabel":"ZipCode",
"value":33081,
"pageNumber":"1"
}
]
}
}
]
}
}
]
}
]
}
You can not update template tabs upon creation of the envelope at this time.
Your signHereTabs is in your inlineTemplate, which will add additional tags to your envelope.
If you want to update tabs that are contained in a template via the API, your workflow should look like:
Create Envelope - ("status" : "created")
Modify Envelope - Edit tags here
Send Envelope
All of the documentation around building this workflow is located in DocuSign REST API Guide
I trying to get a youtube channel banner from the youtube api.
But this is very weird.
I use this code:
$json1 = file_get_contents("http://gdata.youtube.com/feeds/api/partners/$channel/branding/default?key=[api-key]&alt=json");
$data1 = json_decode($json1, true);
$banner = $data1['entry']['yt$option'][15]['$t'];
echo $banner;
Now the weird thing, when i refresh te page i get everytime a new value. but sometimes it will stay one value and thats what i need but after some thime the value is changing...
This is the json code:
{
"version":"1.0",
"encoding":"UTF-8",
"entry":{
"xmlns":"http://www.w3.org/2005/Atom",
"xmlns$yt":"http://gdata.youtube.com/schemas/2007",
"id":{
"$t":"http://gdata.youtube.com/feeds/api/partners/rebasenetwork/branding/default"
},
"published":{
"$t":"2014-02-28T22:08:37.000Z"
},
"updated":{
"$t":"2014-02-28T22:08:37.000Z"
},
"category":[
{
"scheme":"http://schemas.google.com/g/2005#kind",
"term":"http://gdata.youtube.com/schemas/2007#branding"
}
],
"link":[
{
"rel":"self",
"type":"application/atom+xml",
"href":"http://gdata.youtube.com/feeds/api/partners/rebasenetwork/branding/default"
},
{
"rel":"edit",
"type":"application/atom+xml",
"href":"http://gdata.youtube.com/feeds/api/partners/rebasenetwork/branding/default"
}
],
"yt$option":[
{
"$t":"0",
"name":"channel.banner.image_height.int"
},
{
"$t":"http://i1.ytimg.com/u/Yd24MzwIk2gLiv79JNPGSA/channels4_mobile_banner_hd.jpg?v=52d6ad2b",
"name":"channel.banner.mobile.hd.image.url"
},
{
"$t":"http://i1.ytimg.com/u/Yd24MzwIk2gLiv79JNPGSA/channels4_tablet_banner.jpg?v=52d6ad2b",
"name":"channel.banner.tablet.medium.image.url"
},
{
"$t":"https://lh6.googleusercontent.com/-6xCc8OBY5Qk/UtatKX2WY3I/AAAAAAAAAAY/6-vpTOgd0yU/w854-fcrop64=1,00000000ffffffff/channels4_banner.jpg",
"name":"channel.banner.tv.low.image.url"
},
{
"$t":"https://lh6.googleusercontent.com/-6xCc8OBY5Qk/UtatKX2WY3I/AAAAAAAAAAY/6-vpTOgd0yU/w1280-fcrop64=1,00000000ffffffff/channels4_banner.jpg",
"name":"channel.banner.tv.medium.image.url"
},
{
"$t":"#000000",
"name":"channel.global.color"
},
{
"$t":"http://i1.ytimg.com/u/Yd24MzwIk2gLiv79JNPGSA/channels4_banner.jpg?v=52d6ad2b",
"name":"channel.banner.image.url"
},
{
"$t":"http://i1.ytimg.com/u/Yd24MzwIk2gLiv79JNPGSA/channels4_mobile_banner_low.jpg?v=52d6ad2b",
"name":"channel.banner.mobile.low.image.url"
},
{
"$t":"True",
"name":"channel.modules.show_comments.bool"
},
{
"$t":"https://lh6.googleusercontent.com/-6xCc8OBY5Qk/UtatKX2WY3I/AAAAAAAAAAY/6-vpTOgd0yU/w2120-fcrop64=1,00000000ffffffff/channels4_banner.jpg",
"name":"channel.banner.tv.image.url"
},
{
"$t":"http://i1.ytimg.com/u/Yd24MzwIk2gLiv79JNPGSA/channels4_tablet_banner_hd.jpg?v=52d6ad2b",
"name":"channel.banner.tablet.hd.image.url"
},
{
"$t":"Welcome to our network Channel. We help Youtubers to earn money and grow with their channel. Being famous on youtube is one of the things you dream about, isn't it? Let us help make your dreams true!\n\nWith us you can choose your own partnership, You also select what you want to earn from your youtube channel! Are you ready to start growing? Partner Now!",
"name":"channel.global.description.string"
},
{
"$t":"http://i1.ytimg.com/u/Yd24MzwIk2gLiv79JNPGSA/channels4_mobile_banner_medium_hd.jpg?v=52d6ad2b",
"name":"channel.banner.mobile.medium_hd.image.url"
},
{
"$t":"https://lh6.googleusercontent.com/-6xCc8OBY5Qk/UtatKX2WY3I/AAAAAAAAAAY/6-vpTOgd0yU/w1920-fcrop64=1,00000000ffffffff/channels4_banner.jpg",
"name":"channel.banner.tv.high.image.url"
},
{
"$t":"http://i1.ytimg.com/u/Yd24MzwIk2gLiv79JNPGSA/channels4_mobile_banner.jpg?v=52d6ad2b",
"name":"channel.banner.mobile.medium.image.url"
},
{
"$t":"http://i1.ytimg.com/u/Yd24MzwIk2gLiv79JNPGSA/channels4_mobile_banner.jpg?v=52d6ad2b",
"name":"channel.banner.mobile.image.url"
},
{
"$t":"True",
"name":"channel.related_channels.show.bool"
},
{
"$t":"KQvIpdiWrSI",
"name":"channel.unsubscribed_trailer.video_id.string"
},
{
"$t":"http://i1.ytimg.com/u/Yd24MzwIk2gLiv79JNPGSA/channels4_tablet_banner_extra_hd.jpg?v=52d6ad2b",
"name":"channel.banner.tablet.extra_hd.image.url"
},
{
"$t":"http://i1.ytimg.com/u/Yd24MzwIk2gLiv79JNPGSA/channels4_tablet_banner_low.jpg?v=52d6ad2b",
"name":"channel.banner.tablet.low.image.url"
},
{
"$t":"True",
"name":"channel.modules.moderate_comments.bool"
},
{
"$t":"Network partner partnership rebase network pewdiepie",
"name":"channel.global.keywords.string"
},
{
"$t":"Rebase Network",
"name":"channel.global.title.string"
},
{
"$t":"http://i1.ytimg.com/u/Yd24MzwIk2gLiv79JNPGSA/channels4_mobile_banner_extra_hd.jpg?v=52d6ad2b",
"name":"channel.banner.mobile.extra_hd.image.url"
}
]
}
}
This is the one i need(just the url):
{
"$t":"http://i1.ytimg.com/u/Yd24MzwIk2gLiv79JNPGSA/channels4_tablet_banner_extra_hd.jpg?v=52d6ad2b",
"name":"channel.banner.tablet.extra_hd.image.url"
},
Can someone help me please? i really don't understand why it's changing the value every refresh..
You can loop through the results and print out the one where the name matches channel.banner.mobile.extra_hd.image.url
$data1 = json_decode($json1, true);
foreach ($data1['entry']['yt$option'] AS $banner) {
if ($banner['name'] == 'channel.banner.mobile.extra_hd.image.url') {
print $banner['$t'];
}
}