Solved

[Tips & Scripts] Flexible Form Fields


Userlevel 3
  • Former Unbouncer
  • 23 replies

A feature we get asked for a lot is the ability to create forms in more flexible and creative ways, like multi-column forms, horizontal forms, different sizes for input fields etc.

This solution tackles all of the above by allowing you to place the form fields anywhere you want on the page and choosing the width of each field individually. The only limit is your imagination!

Check out the final product built in Unbounce here:
http://unbouncepages.com/split-form-fields/

flexible form fields unbounce


How to Install in Unbounce

Click Here for Instructions

🚨
This is not an official Unbounce feature. This functionality is based entirely on third party code, and has only been tested in limited applications. Since this isn’t a supported Unbounce feature, our support team will be unable to assist if things go awry. So if you are not comfortable with HTML, Javascript and CSS, please consider consulting an experienced developer.


Scripts Needed

Grab the javascript needed here:
https://gist.github.com/victorzen/9a0294e0e65c03e4b23183e0b58d2118

Instructions

Step 1. Add a box for each form field and make your design. The width of the fields will adapt to the width of the boxes.  

Step 2. Copy and paste the following snippet in the Javascript section with placement ‘Before Body End Tag’.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>

Add the script found here below the snippet and replace #lp-pom-box-01, #lp-pom-box-02, etc. with the IDs of your boxes.  



Step 3. Change the opacity of the boxes to zero and select “border: none”. Make sure to send the boxes backwards so they don’t block your form fields.  



Step 4. Save and republish to see it in action!


Testing

Like anything else you implement on your page, you’re going to want to test this out thoroughly to see what effect (if any) it has on your conversion rates.

We recommend running an A/B test and segmenting a small portion of traffic towards the page - just to be safe.

Conclusion

This is an incredibly simple way to get your forms look the way you want them and opens a door for exciting design possibilities!

Give it a try and please let us know what you think. Happy converting! 🍾


Can’t see the instructions? Log in or Join the Community to get access immediately. 🚀


Want to take your Unbounce landing pages + Convertables™ to the next level?
:spinbounce: Check out the Ultimate List of Unbounce Tips, Scripts & Hacks

icon

Best answer by winnieko 9 March 2020, 18:39

View original

57 replies

@winnieko thank you for this. The original script wasn’t working for me but when i used your modification it worked!

Hi Vic, Same here, the if/else won’t work as expected.

Code here if anyone spot the issue.

if(jQuery(Window).width()) >=600 {
    jQuery.ready(function($) jQuery(document).ready(function($) {
    
    //Change #lp-pom-box-01, etc. for the IDs of the boxes where you want the form fields to display.
    var boxes = ["#lp-pom-box-319",
                 "#lp-pom-box-316",           
                 "#lp-pom-box-318",
                 "#lp-pom-box-321",
                 "#lp-pom-box-322",
                 "#lp-pom-box-323"];
    
    $('.lp-pom-form .lp-pom-form-field')
      .each(function(i, field) {
        $(field)
          .offset($(boxes[i]).offset())
          $(this).children().width($(boxes[i]).width()-16)
      });    
  });
  }
  else{}

OMG, Thank you! This worked!

For some reason, I cannot grab the individual ids for each form cell. Is this a new update?

Hi Vic

Wow, this is really amazing. Thank you soo much. This will give me and my team more possibilities in styling forms. Awesome 🙂

How do you manage to place 3 forms to your landingpage? Or is this just an example to illustrate your script? I’m searching a way to have two forms on one page.

Thank you already in advance for any help 🙂

HI Vic,

Sorry to bring up an old post, but I’m working on the flexible form fields and I can get it to either show on mobile, or on desktop but not both. Do I need to use the mobile code you posted to enable this to work?

Thanks

Julz

Userlevel 1

Hi there! Yes, this still works 🙂 You can see it on this page here:

http://unbouncepages.com/custom-flexible-form-fields/

However, I found that it works when I removed the “lp.” from the script. I hope that helps!

<script>
/**
    * Do not remove this section; it allows our team to troubleshoot and track feature adoption. 
    * TS:0002-08-042
*/
  jQuery(document).ready(function($) {
    
    //Change #lp-pom-box-01, etc. for the IDs of the boxes where you want the form fields to display.
    var boxes = ["#lp-pom-box-01",
                 "#lp-pom-box-02",           
                 "#lp-pom-box-03",
                 "#lp-pom-box-04"];
    
    $('.lp-pom-form .lp-pom-form-field')
      .each(function(i, field) {
        $(field)
          .offset($(boxes[i]).offset())
          $(this).children().width($(boxes[i]).width()-16)
      });    
  });
</script>

Can anyone confirm that this still works?

Hi, I’m having the exact issue you described, it’s adding extra space to the right of the page. Were you able to find a solution to this?

I can’t seem to get this to work on any of my forms. Is this script out of date? I’ve copied it word for word, step-by-step, and it doesn’t do anything.

This seems not to work anymore. At least to me. The code provided does absolutely nothing.
Is this somehow connected to jquery removal?

Hi,
I´ve been reading the thread but apparently no one went into this issue before.
These forms (in the gif attached) seem to work nicely.
But the cursor only allows the user to type something in the lower part of the field.
From the middle part up, the cursor becomes an arrow and prevents the user from typing.

Any ideas why this might be happening?

Desktop version live at: https://test.baisargentina.com/2-fields-test/
Thanks!
com-video-to-gif%20(1)

Hi @Vic,
I’m currently trying to make these flexible fields work but I have pain doing it Is it possible to make a video call so that you can help me make it work ?
Shouldn’t be long !
Thanks in advance for your help
Best,
Arnaud

Thanks for the Great Script People… it definitely saved me solid time… One question however, can i make multiple submission buttons on the page ?

I don’t remember what I did, but I’m having the same trouble again. I add form items, add the appropriate boxes, add the box #IDs to the script, but it won’t add the new ones.

http://unbouncepages.com/August-enewsletter-2

I’m inspecting the code of the page and it’s just not plugging the form information in.
Any ideas?

Userlevel 5
Badge +2

Does this add any extra space to the right side of the page for anyone else?
When I remove the script the space is no longer there. Can anyone assist… @Vic ?

In addition to this I have found a work around for the desktop/mobile issue. (Mine was only working properly on load and if i resized the window, it would not work - which I realize that a user will usually just see one version, but a client will most likely view mobile on a desktop)

It is a bit wonky… but it works.

Just copy the fields on the mobile editor, hide the old ones, and place the corresponding fields in the script.

<script>
  
  $(document).ready(function() {

    var windowType;
    var $wind = $(window);

    var mobileCheck = function() {
        var window_w = $wind.width();
        var currType = window_w < 940 ? 'mobile' :'desktop';

        if (windowType == currType) {
            
            return;
        } else {
            windowType = currType;
        }

        if (windowType == 'mobile') {                
                          lp.jQuery(document).ready(function($) {
    
    //Change #lp-pom-box-01, etc. for the IDs of the boxes where you want the form fields to display.
    var boxes = ["#lp-pom-box-175",
                 "#lp-pom-box-176",           
                 "#lp-pom-box-177",
                 "#lp-pom-box-178",
                 "#lp-pom-box-179",
                 "#lp-pom-box-180",
                 "#lp-pom-box-181"];
    
    $('.lp-pom-form .lp-pom-form-field')
      .each(function(i, field) {
        $(field)
          .offset($(boxes[i]).offset())
          $(this).children().width($(boxes[i]).width()-16)
      });    
  });
        } else {
              lp.jQuery(document).ready(function($) {
    
    //Change #lp-pom-box-01, etc. for the IDs of the boxes where you want the form fields to display.
    var boxes = ["#lp-pom-box-151",
                 "#lp-pom-box-152",           
                 "#lp-pom-box-146",
                 "#lp-pom-box-147",
                 "#lp-pom-box-148",
                 "#lp-pom-box-149",
                 "#lp-pom-box-150"];
    
    $('.lp-pom-form .lp-pom-form-field')
      .each(function(i, field) {
        $(field)
          .offset($(boxes[i]).offset())
          $(this).children().width($(boxes[i]).width()-16)
      });    
  });
        }
    }

    mobileCheck();
    var resizeTimer;

    $wind.resize(function() {
        if (resizeTimer) {
            clearTimeout(resizeTimer);
        }

        resizeTimer = setTimeout(mobileCheck, 300)
    });

});
  
</script>

If anyone has an alternative to this, please share!!

Thanks!

Wow @JasonRoach, love your page! How did you get those checkboxes with images done?

Hello!

Thank you for this script. I’m using it on several pages and it’s working great.
I generated a new page based on an old one, and can’t seem to get the form fields to display.
Could you please check it out?
http://unbouncepages.com/november-enewsletter-1/

The second set of three boxes should also have checkboxes at the top.

Userlevel 3

Specially for you friend! 🤣

OMG Vic!

I freaked out cause I thought the github link was created specially for me since it has my name on the url hahahahahaha

😂

Hi,

I’m trying to create a mobile view with a flexible form. If I preview the mobile view, the preview shows me the boxes of the desktop view. I have used the script, which “fires any code on mobile or desktop”, too. I even have created seperate boxes for mobile view and disabled the view of the boxes for the desktop view, but still only the desktop boxes are shown. I have change something on the mobile view and press save and refresh the preview, it takes the boxes of the mobile view and also shows them on the desktop view.

I have already spent some hours to figure out why this happens, would be great if someone could help me out here.

Best and also thanks for the great script.
Kurbm

I implemented the flexible form fields. The error message div is overlapping with the form how can I change the position of the box.

Hello,

I was trying to create the flexible form fields using the steps, but I was not able to see the expected result.Can you add the images of each steps. It would be great If we have the images of how to create each step.

Vic,

I applied the code as you mentioned but for some reason Unbounce is showing me the script on Orange, meaning something is wrong. The form does works as intended, script to work on desktop but not on mobile. Here is the code. What could be wrong?. Could you let me know?. Thanks.

Hi,

I have been trying this script on a new page I’m making. It works great (Thanks!) except for one thing.
One of the form fields can’t be selected.

So I made a page that has a monster form with 34 fields. When I tried it out in preview, and live, two of the fields would not work properly. All of the boxes are sent as far back as possible, and the form itself is sent as far forward as possible.
After deleting the two boxes, copying a box that worked, and pasting it two times, one of the fields in the newly pasted boxes started working. I naturally tried the same thing a few more times for the one that still wasn’t working. But after 5-6 times I gave up. I instead deleted the malfunctioning box and made a completely new one. I of course altered the script to reflect the new boxes names at all times. I sent the new box back as far as I can, but it still won’t work.

I even tried having the box display another form field, but that didn’t change anything. It was always the same box that didn’t work.

However, the field is properly displaying. And it is actually possible to select it by tabbing. And when selected, you can type in it. So it seems to work in every way, except that you can’t click the field to select it.

Any ideas?
Is there any thing else that could be blocking the form field? Is there anything else that I might have to do to make it accessible?

I have tried with both radio buttons (which is what I would prefer) and just a plain text field. Exact same result with both.

Very grateful for any help!

EDIT: I finally realized what the issue was! It was the positioning of the boxes. I had placed the two boxes too close together, although they didn’t overlap visually, the actual (but invisible) size of the form fields would cover each other. And even if one field was “in front” of the other, it made it impossible to select either one of them. Moving the fields further apart solved the problem for me.
Perhaps stupid of me to not realize it sooner, but using the visual editor sometimes makes you forget what is not seen 😉 Hope this might help anyone else out there with a similar issue!

Thanks again for the script, works really well!
Praying that this kind of flexibility becomes a built in feature soon

Reply