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

Question

Question

Creating a custom header (with logo) using JavaScript

asked on June 5, 2017 Show version history

Hi this is my first time posting so sorry if this has been mentioned on here before. 

 

I  am currently trying to create a custom header for a form using JavaScript. Unfortunately so far

 I haven't had much luck, my attempts have only had the logo appearing underneath the form title (shown in attached image).

 

Would anyone happen to have any thoughts on how to get the logo to appear above the form title field? 

 

the script i was using is as follows (i have since removed the image location i was using) : 

 $('<head><img src="[insert image location here]" style="margin-left: auto;margin-right: auto;display: block;width;100%;"></head>').insertBefore($('.cf-form'));  

 

To be honest i'm still learning some of what JavaScript can do, as such the script above is me trying to  re-purpose a line of script that a colleague used for footnotes, into one for headers frown apologies if I've butchered it!

 

Many Thanks, 

 

Chris 

Capture.JPG
Capture.JPG (50.01 KB)
0 0

Answer

SELECTED ANSWER
replied on June 7, 2017

Chris,

If you want the header to show up on the completed Form, then you need to use Custom HTML elements and CSS. Anything added through JavaScript won't stay on the Form after it is saved to the repository and might also cause problems when viewing the form for approvals.

Instead, I would recommend using "position:absolute;" on your Custom HTML element to get it where you want it

div#<Id of your custom element>{
   position:absolute;
   top:0;
}

then, push the rest of the form down as much as you need

div.cf-formwrap {
   margin-top:200px;
}

However, if you want to have your custom image within the curved border you will need to get fancier. In that case you would need to pad the top of the Title element (div#cf-formtitle) to make room for the image instead of shifting the entire form down.

As Rui mentioned, in that case you could just upload a Logo to Forms and apply that to the form. Even if it is not exactly where you want it you could use CSS to shift things around as needed, and that would be far more effective and reliable than JavaScript.

1 0
replied on June 8, 2017

Hi Jason,

thanks for the answer, its not working 100% for me but i shall keep trying :) it does look like it is the way to do it. Thanks for all the help!  

 

 

0 0
replied on June 8, 2017

Hi Chris,

It is definitely going to take some adjustments for things like height, width, alignment, etc. but that should at least get you in the right direction. I had something like that on one of my forms and it took some fine tuning. However, it wasn't so bad when I pulled up the form preview in Chrome and used Inspect on the element so I could make adjustments to the CSS and see how the changes affected it in real time.

1 0
replied on June 13, 2017

Hi Jason, 

 

inspect is a really great idea thanks for the heads up, i shall give it a try. I managed to get the custom html box to appear in the right place after a few tries, definitely a lot easier than JavaScript.

0 0

Replies

replied on June 5, 2017

I'm sure there are many ways of doing this.

One way that I can think of would be to use the built-in setting to hide the title all together. Then you could use the Custom HTML field to make your own.

noTitle.png
CustomHTMLField.png
noTitle.png (9.97 KB)
2 0
replied on June 5, 2017

Hi Chris,

How would you like the logo to be placed? Why not use the built-in customizing logo on themes? 

Besides, I agree with Raul that using custom HTML field is be better than insert html with custom script.

1 0
replied on June 6, 2017

Hi Rui and Raul,

Thanks for taking the time to help smiley I was trying to get the logo to appear above the form name. My company uses various different forms but would prefer the logo and the form name to be shown at the same time.  

 

Chris 

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

Sign in to reply to this post.