Hi Jean-Claude,
I thought I'd written a FAQ about this but apparently not.
Later: I've modified this post a little and added it to
this FAQ.
It's easy to include files into ChronoForms and I do it with almost any code that is more than about twenty lines. Then I can edit it with an FTP enabled editor that has a built in linter for highlighting code errors (I use Sublime Text 2).
You can include files into textarea boxes in many ChronoForms elements and actions provided that they evaluate PHP when they are run. (The exceptions I can think of at the moment are options boxes of Radio Button and Checkbox groups* and the Thank You Message action**).
I have a macro set up that inserts this code into a textarea:
<?php
include (JPATH_SITE.DS.'components'.DS.'com_chronoforms'.DS.'includes'.DS.$form->form_details->name.DS.'file_name.php');
?>
Note .DS. is deprecated in Joomla! 3; a simple / should work OK.This will automatically add the form name to the path; replace file_name with the name of your file: I typically use on_load_a.php, on_load_b.php, on_submit_a.php, . . .
For code that is specific to a form I use:
[list]
Custom Code actions to insert PHP that is pre-processing data;Load JS actions to insert JavaScript files load_js.js;Custom Element elements to insert HTML with PHP that is directly related to the HTMLLoad CSS files to add CSS (though more often I type this directly in the action)[/list]
For code that is related to several forms I'll probably put it directly in the 'includes' folder. For example, as a helper file with functions that are used in several files.
For third-party code, like API libraries, I typically create a components/com_chronoforms/extras/ folder*** and add libraries in sub_folders there.
See the screenshot below for the structure of my J3 test site - it's easier to see than to describe.
For completeness you can use Joomla! code to load CSS and JavaScript files (or snippets) into the page header.
<?php
$doc =& JFactory::getDocument();
$doc->addScript('url_of_js_file.js');
$doc->addScriptDeclaration('some js snippet');
$doc->addStyleSheet('url_of_css_file.css');
$doc->addStyleDeclaration('some css snippet');
// code to force the MooTools library to load
// this is sometimes needed to handle the load sequence
JHTML::_load('behaviour.mootools'); // Joomla! 2.5 and earlier
JHTML::_('behavior.framework'); // Joomla! 3 MooTools core only
JHTML::_('behavior.framework', true); // Joomla! 3 MooTools core + more
// code load the JQuery library to load (Joomla! 3 only)
JHtml::_('jquery.framework'); // load jQuery in no conflict mode
// code to load the Bootstrap library (Joomla! 3 only)
JHtml::_('bootstrap.framework');
?>
Please see
the Joomla docs for more info on these methods in Joomla! 3 and their limitations.
There are more things that you can do but this should be enough to get you started.
Bob
* Use the Dynamic Data options with PHP to pre-process the data if needed.
** Use a Custom Code action in place of the Thank You page action.
*** I keep the included files and folders inside the components/com_chronoforms folder for convenience but you can have them anywhere that is accessible.