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

Question

Question

How to insert Form Fields inside HTML content (to maintain formatting of paper forms)

asked on August 15, 2023

Greetings,

I am creating the digital version of a paper form, and I find myself in an interesting dilemma that I would like to be able to achieve to maintain the structure of the form as it is designed.
It would be possible to be able to insert the fields to be filled inside a text section (I assume the most logical thing is inside an HTML section), and play with the position of the fields inserting them in the texts, but as far as I know, I can only show the values of these fields within the HTML sections, but I have never seen the possibility that fields can be placed within the HTML section to be filled, do you know of any way or alternative to be able to do something similar to the image What do I leave you next in Laserfiche 10 form?

membershippp.png
membershippp.png (164.19 KB)
0 0

Answer

SELECTED ANSWER
replied on August 15, 2023

I've done this with the Classic Designer (it would be very hard or even impossible to do this with the Modern Designer).  Since I see you tagged your post as Version 10, Classic Designer is all you have anyway, so that's a moot point.

Here's an example (tested on Classic Designer Version 11.0.2212.30987).

This example includes a custom HTML element with three paragraphs of text (just using some lorem ipsum for example).  This also includes 6 span elements within it, that give it locations for the fields to be moved to and any associated errors to be moved to as well.  There are also two single line fields (currency fields specifically in this example) and one checkbox field.

Here's how it looks in the Layout designer:

Here's the actual HTML of that Custom HTML element, with the 6 span elements within it.

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Transaction amount: $ <span id="field1_placeholder"></span> Dictum sit amet justo donec enim diam vulputate ut. Quis risus sed vulputate odio ut enim blandit volutpat. Faucibus a pellentesque sit amet porttitor. Massa tincidunt nunc pulvinar sapien et. Sagittis orci a scelerisque purus semper eget.</p><span id="field1_errors"></span>

<p>Faucibus nisl tincidunt eget nullam non. Nunc sed velit dignissim sodales ut eu sem. Transaction amount: $ <span id="field2_placeholder"></span> Adipiscing vitae proin sagittis nisl rhoncus mattis rhoncus urna neque. Nunc lobortis mattis aliquam faucibus purus in massa tempor nec. Donec pretium vulputate sapien nec sagittis aliquam malesuada. Iaculis eu non diam phasellus vestibulum lorem sed.</p><span id="field2_errors"></span>

<p>Mattis vulputate enim nulla aliquet porttitor lacus. Est placerat in egestas erat imperdiet sed euismod. Checkbox field: <span id="field3_placeholder"></span> Arcu bibendum at varius vel pharetra vel turpis nunc. Aliquet porttitor lacus luctus accumsan tortor posuere ac ut consequat. Id aliquet risus feugiat in ante metus dictum.</p><span id="field3_errors"></span>

 

This Javascript is used to move the fields and their errors messages into those 6 span elements of the paragraph: 

$(document).ready(function() {
  
  //Move the single line field elements into the paragraph.
  //Give them new class names we can refer to later.
  $('.field1_original input').addClass('field1_new').appendTo('#field1_placeholder');
  $('.field2_original input').addClass('field2_new').appendTo('#field2_placeholder');
  
  //On the readonly or archival version of the form, move the 
  //single line field elements into the paragraph.
  $('.field1_original .ro').addClass('ro_underline').appendTo('#field1_placeholder');
  $('.field2_original .ro').addClass('ro_underline').appendTo('#field2_placeholder');
  
  //Move the checkbox field elements into the paragraph.
  //Give them new class names we can refer to later.
  $('.field3_original .radio-checkbox-fieldset').addClass('field3_new').appendTo('#field3_placeholder');
  
  //On the readonly or archival version of the form, move the 
  //checkbox field elements into the paragraph.
  $('.field3_original .ro').closest('.cf-field').appendTo('#field3_placeholder');
  
  //Hide the left-over components from the original field positions.
  $('.field1_original').hide();
  $('.field2_original').hide();
  $('.field3_original').hide();
  
  //Using their new class names, we set-up listeners for after the single line fields
  //are changed or lose focus, to move any parsley errors to their new locations.
  //This references the placeholders when looking for parsley-errors-list, because with
  //single line fields, the parsley-errors-list is appended to the input element.
  $('.field1_new').blur(moveSingleLineErrors);
  $('.field1_new').change(moveSingleLineErrors);
  $('.field2_new').blur(moveSingleLineErrors);
  $('.field2_new').change(moveSingleLineErrors);
  function moveSingleLineErrors() {
    $('#field1_placeholder .parsley-errors-list').appendTo('#field1_errors');
    $('#field2_placeholder .parsley-errors-list').appendTo('#field2_errors');
  }
  
  //Using their new class names, we set-up listeners for after the checkbox fields
  //are changed or lose focus, to move any parsley errors to their new locations.
  //This references the original field when looking for parsley-errors-list, because with
  //checkbox fields, the parsley-errors-list is not appended to the input element, and
  //therefore it will be in the original location, not the new location.
  $('.field3_new input').blur(moveCheckboxErrors);
  $('.field3_new input').change(moveCheckboxErrors);
  function moveCheckboxErrors() {
    $('.field3_original .parsley-errors-list').appendTo('#field3_errors');
  }
  
});

 

I also included this CSS that impacts the fields after they are moved to their new locations.

/*Adjust width of the two single line fields.*/
.field1_new {width: 100px;}
.field2_new {width: 100px;}

/*Needed to ensure checkbox fields are inline with paragraph.*/
.field3_new {display: inline;}

/*Make readonly version of form fields underlined.*/
.ro_underline {border-bottom: 0.1rem solid;}

 

The end result looks like this:

And when error messages are present:

And when the form is populated:

And the readonly/archival version of the form:

2 0
replied on August 15, 2023

Thank you very much, I will get to work immediately to implement this alternative, I will let you know as soon as I can have it made of my progress. But your explanation has been very useful.

0 0
replied on August 15, 2023

You're very welcome.

0 0
replied on August 15, 2023

It has been amazing, now with your help it opens up the possibility of reformatting and redesigning several forms that I had previously made with similar formats. Here I show you how the readjustment of the current form that I am working on is going.

Very thankful!

membershippp-ok.png
1 0
replied on August 15, 2023

I'm so glad you like it and that it helps you.  Your form looks great by the way!

1 0
replied on August 15, 2023

Thank you very much for your compliment, I still have several similar fields to implement, the truth is that your contribution came very well to what I am doing. After one has a working solution to a problem, then we can play a bit with CSS to make it more visually appealing, without losing the standards that clients require. yes 

0 0
replied on August 15, 2023

By the way, how can I make the labels of the radio buttons bold in the CSS? I have tried it in several ways but it does not apply to me.

0 0
replied on August 16, 2023

Here's some CSS to make the checkbox or radio button labels bold.  

/*Bold text on all checkbox/radio button labels.*/
.form-option-label {font-weight: bold!important;}

/*Bold text on specific checkbox/radio button labels - add 
the boldCheckbox class to the specific fields.*/
.boldCheckbox .form-option-label {font-weight: bold!important;}

 

1 0
replied on August 16, 2023

Thank you, that works perfect!!!

0 0

Replies

replied on August 15, 2023

I know you already have a working solution so stick with that, but I wanted to mention another approach which is to create two separate forms, one for filling out, and one for storage.

The web form will still look like a typical web form, but then I'll create another version of the form that's more like the "paper" layout and use dataset variables in HTML to populate the data.

This doesn't work if you need the form to be printable right after submission, but other than that you can specify that second form with "using current process data" in things like Save to Repository, emailing the form, etc., to get the desired format.

Things like checkboxes and radio buttons get a little more complicated and I may use a mix of HTML and actual fields, but it still works great for striking a balance between getting the desired format while still keeping the user side more web/user friendly.

1 0
replied on August 15, 2023

Somehow I think you read my mind, and what you recommend is very accurate, and it's just what I plan to do so that the form saved on the server (although I plan to store both separately) is as clean as possible. Thank you very much for your recommendation, I think it complements cases like this very well. yes

0 0
replied on August 15, 2023

You're quite welcome. The thing to keep in mind is that the dataset variables are only updated on submission so they can't be used for "real-time" updates of the web form in the same way as Matthew's solution, but that's not an issue if the second form is only used for document generation not data collection.

I haven't worked with the modern designer much yet since my forms are often too dependent on JavaScript functionality, but this approach should work there too.

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

Sign in to reply to this post.