You are viewing limited content. For full access, please sign in.

Question

Question

Attaching Screenshots to a Form - Is it possible?

asked on May 5, 2022

Hello,

I've worked out how to create a text box for a user to paste a screenshot into a form, for example when they need to evidence funds in a bank account:

But on form submission, the screenshot image is lost regardless of the next activity. Is there a way to get around this?

 

Or better yet, can I create a comments box in Laserfiche Forms that is like the comments box we use in Laserfiche answers?

 

The html code that I use is very simple:

<style>
p {
  border: 1px solid lightgrey;
  border-radius: 8px;
  width: 93%;
}
</style>


<h5>Upload screenshot image here</h5>
<p contenteditable="true"><br><br></p>

 

Many thanks in advance!

0 0

Replies

replied on May 6, 2022

If you have made your own field as a custom html element, there is no way for the system to save the value in the field and then display it on subsequent forms (without a bunch of custom Javascript).

I would recommend using an upload field to attach the screenshot instead.

1 0
replied on May 9, 2022

Thanks Matthew, our JavaScript guru did try and find a plugin to use where it would allow the user to copy and paste into an upload field but had no luck.

0 0
replied on May 9, 2022

Yeah, they would have to save their screenshot and then upload it.  I encourage our staff to do similar with the built-in Snipping Tool in Windows.

If you want to use the custom field you've made, you'll need to get creative determining a way to save the values - and it's going to take a bit of Javascript.

One possible way to make this would would be having the contents of your custom HTML field copied into a hidden field, and then copied back into your custom field when the form is loaded during later tasks.  I haven't done this myself, so I can't specifically address how this will play out - but I do have a somewhere similar example that we use - we use signature pads and the signature image is saved in a hidden multi-line field, and then we have Javascript that converts that encoded image back into a visiable image and adds it to the form for display.  Since I don't know how your custom HTML field is storing the data for the attached image, I can't guess whether this method would work or not.

If you wanted to try to play around with that, here's an example that may help (without the specific part about using signature pads).  This takes the stored signature image from the user profile and displays it on the form.

Add 4 fields to your form:

  • single-line - name: user_name - class name: username
  • single-line - name: user_id - class name: userid1
  • multi-line - name: sig_data - class name: sigdata1
  • custom html - class name: sigimage1 - html: 
    <b>User Profile Signature<br></b><div id="oldsigimage1"></div> <div id="mm100" style="left: 0px; top: 0px; width: 100mm; height: 100mm; position: absolute; z-index: -1;"></div>
    

 

Add these lookups on those four fields from your LFForms database:

 

Add this Javascript: 

$(document).ready(function () {

  //this section deals with applying the 1st signature image from a prior task in the process
  var activeSigValue1 = $('.sigdata1 textarea').val();
  var archiveSigValue1 = $('.sigdata1 .cf-field').text();
  if (activeSigValue1 != undefined && activeSigValue1 != '')
  {
    var decoded = HtmlDecode(activeSigValue1);
    var $img1 = $('<img style="background-color:white;" class=imported1></img>');
    $img1.attr("src", decoded).appendTo('#sigimage1');
  }
  //this section deals with applying the 1st signature image on the submitted form
  else if (activeSigValue1 == undefined && archiveSigValue1 != '')
  {
    var decoded = HtmlDecode(archiveSigValue1);
    var $img1 = $('<img style="background-color:white;" class=imported1></img>');
    $img1.attr("src", decoded).appendTo('#sigimage1');
  }

}); //end of $(document).ready(function () {

//function used for encoding the image to URI data
function HtmlEncode(value)
{
  return $('<div/>').text(value).html();
}

//function used for decoding the URI data to an image
function HtmlDecode(value)
{
  return $('<div/>').html(value).text();
}

//This section deals with applying the 1st signature image from the loaded date
$(document).on("lookupcomplete", function (event) {
  var activeSigValue1 = $('.sigdata1 textarea').val();
  console.log('test: ' + activeSigValue1);
  if (activeSigValue1 != undefined && activeSigValue1 != '')
  {
    if ($(".imported1").length)
    {
      //clear the existing signature image on the screen
      $(".imported1").remove();
    }
    var decoded = HtmlDecode(activeSigValue1);
    var $img1 = $('<img style="background-color:white;" class=imported1></img>');
    $img1.attr("src", decoded).appendTo('#sigimage1');
  }
});

 

End result is a form that pulls in the image data from the database (it could be any image - but I know this one works from the signature, so it was a good place to start) and displays it on the form:

0 0
replied on May 10, 2022

Thanks Matthew, much appreciated - I'll have a play around with that!

0 0
replied on May 5, 2022

Give them an upload button instead?

0 0
replied on May 9, 2022

Thanks, just trying to reduce the amount of clicks for the users, although looking at what Matthew Tingey has said it doesn't look like it's possible without JS frown

0 0
replied on May 5, 2022

Do you make the field "read only" on next task? Maybe is like signature, that if you le it open, the signature is lost unless you make it read only.

0 0
replied on May 9, 2022

Didn't work with the read-only frown

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.