Forums

Dynamic link to css for chronoforms

Ron 13 Jan, 2012
Hello,

I want to have a dynamic link to all my forms maybe put in the index.php of my joomla site so that I don't have to add a css file every time I create a form.

example:

<link rel="stylesheet" href="/components/com_chronoforms/css/forms.css" type="text/css" />


Do I just add it in the form html ? I would like it to be added to the index.php file 🤨 How can I do that ... ?

Please help.

Ron
GreyHead 13 Jan, 2012
Hi Ron,

You can edit the index.php file in your template to add it there. But then it will load on every page, not just the form pages.

You could also edit the ChronoForms CSS file that is loaded with the form and either add your CSS there, or put an @import url('some_url'); line at the beginning to import your file.

Bob
Ron 15 Jan, 2012
Thanks Bob,

I really do not know which file to edit and how to add the code.

Is it this code ?

@import url('/components/com_chronoforms/css/forms.css');


Thanks for the help.

Ron
petergoeswest 17 Jul, 2012

Hi Ron,

You can edit the index.php file in your template to add it there. But then it will load on every page, not just the form pages.

You could also edit the ChronoForms CSS file that is loaded with the form and either add your CSS there, or put an @import url('some_url'); line at the beginning to import your file.

Bob



Hi Bob, I have got a quick question about this, what happens when you update Chronoforms, do the Chronoform CSS files get overwritten ? and what method would you suggest?.

Thx in advance Pete.
GreyHead 17 Jul, 2012
Hi Pete,

If you edit the ChronoForms CSS files then they will get overwritten when you upgrade. There's no easy answer to this and no way to turn off the automatic loading of just the CSS files without also turning off the JavaScript files.

I'd probably put the CSS into a separate file and load it from a Custom Code action in the Form On Load event. This is a pragmatic solution rather than an ideal one though as you are probably loading the redundant ChronoForms CSS files as well. In most cases this will make little practical difference.

Bob
petergoeswest 17 Jul, 2012
Hi Bob thx for your quick response, I followed your suggestion, I put a variant of
<link rel="stylesheet" href="/components/com_chronoforms/css/forms.css" type="text/css" />
as a custom code it worked perfectly, which is a bit of a worry, I cant validate the page on my WAMP server to check if it's loading as it should, but I will check it in the morning on my live site.

I was thinking that if it isn't loading in the doc head maybe I could use the Load CSS function because there isn't that much code but I would prefer your method.

Anyway thx again for pointing me in the right direction.
GreyHead 17 Jul, 2012
Hi Pete,

There's a little Load CSS File action here but you can just as easily put this code into a Custom Code action
<?php
$doc =& JFactory::getDocument();
$doc->addStylesheet(JURI::root().'components/com_chronoforms/css/forms.css');
?>

Bob
petergoeswest 18 Jul, 2012
Thx again Bob your amazing! I used your suggestion and also downloaded your load css action, I have 1 more question am I correct in thinking that I could by using this method and create a simple form with only the load custom code action and include the form using the chronoforms plugin to load the form / external css file on most content items eg. Articles ? I hope so because It would make managing my site sooo much easier & better than loading up my template css file like I do now.

Hi Pete,

There's a little Load CSS File action here but you can just as easily put this code into a Custom Code action

<?php
$doc =& JFactory::getDocument();
$doc->addStylesheet(JURI::root().'components/com_chronoforms/css/forms.css');
?>

Bob



I think I am finaly understanding php a little bit, you mentioned (JURI::root()on one of my earlier posts but I didn't get it, but seeing how it's actually used really helped. Thx again.
GreyHead 18 Jul, 2012
Hi Pete,

Hmmm . . . using a ChronoForm to load a CSS file to format articles is a bit like using a sledgehammer to crack a nut . . . I'm not clear what the problem you are trying to solve is though.

Typically your main article CSS is set by the template css file and the template + Joomla! manage the loading.

If you want to load a CSS file on some pages then I would probably do that using Jumi (an extension that lets you add PHP to pages) and add the code from my post here to a Jumi module on those pages. It's a very flexible way of adding custom PHP to Joomla pages.

I use JURI::root() because it is site independent and if you want to copy the form to another site; or another user wants to copy the code on their site it will automatically pick up the current site URL root. There are a family of similar methods that you can use - see the Joomla! JURI docs for more info. There's also the JPATH_SITE defined term that will give you the site folder path in a similar way.

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