Signature pad

webcrea 29 Mar, 2018
Hi,

How to add signature pad in a form?

Regards
GreyHead 29 Mar, 2018
Hi Christophe,

Please use the Signature element from the Widgets group in the Designer tab.

Bob
webcrea 29 Mar, 2018
Thanks Bob,
I didn't see it before...
Best regards
webcrea 29 Mar, 2018
How to recover the signature, please?
{data:signature} produces an encoded image in the html
{var:signature} in attached file -> error no email

Thanks
GreyHead 29 Mar, 2018
Hi Christophe,

No answer yet but please see this thread which has the same question.

Bob
webcrea 29 Mar, 2018
Thanks Bob,

The code populates an empty png ...

Regards
webcrea 29 Mar, 2018
$this-> and no $form->
All works except the attached file, i think it comes from the code $form->files...
I tried $this-> but not
Do you have any idea?

<?php
$data_pieces = explode(",", $this->data[signature]);
$encoded_image = $data_pieces[1];
$decoded_image = base64_decode($encoded_image);

// set the folder where the images will be saved
$folder = 'images/signatures/';
$path = JPATH_SITE.'/'.$folder;
$url = JURI::root().$folder;
// sets a file name using a date-time prefix to make sure it is unique
$sig_name = date('Ymd-his').'_signature.png';
file_put_contents( $path.$sig_name, $decoded_image);

// add the file info to the form data
$this->data['signature'] = $sig_name;
$form->files['signature']['name'] = $sig_name;
$form->files['signature']['link'] = $url.$sig_name;
$form->files['signature']['path'] = $path.$sig_name;
// display the image if needed
echo "<img src='{$url}{$sig_name}' />";
// to add the image to an email add this line
// and put {sig_img} in the email template
$this->data['sig_img'] = "<img src='{$url}{$sig_name}' />";
?>
GreyHead 29 Mar, 2018
Hi Christophe,

I was able to display an image by replacing the last five lines (starting //display this image) with
return $url.$sig_name;
and then using this in a Custom Code action
<div><img src='{var:php6}' /></div>
where php6 was the name of my PHP action.

This should also work in an email body - my tests have not been delivered for some reason though the Debugger shows success.

Bob
webcrea 30 Mar, 2018
Hi Bob,
Display image works well.
Only add file to email doesn't work.

$form->files['signature']['name'] = $sig_name;
$form->files['signature']['link'] = $url.$sig_name;
$form->files['signature']['path'] = $path.$sig_name;

I think it's not : $form->files

Regards
GreyHead 30 Mar, 2018
Hi Christophe,

It is not $form->files - but I can't work out what it is.

In my test I tried adding the display div in the email body - I think that should work OK.

Bob
webcrea 31 Mar, 2018
Hi Bob,
Save to directory and img in mail works well.
only attached file doesn't
regards
Chris
GreyHead 31 Mar, 2018
Hi Christophe,

Please try this version - replace the 'return' section of the PHP code with this:
// add the file info into the form data
return array(
'url' => $url.$sig_name,
'path' => $path.$sig_name
);
Then you can use {var:php6.path} in the email body or to display on the site as before and {var:php6.url} in the Attachments list of the Email action. (Replacing php6 with the name of your php action.)

Bob
This topic is locked and no more replies can be posted.