Using javascript in Wordpress Chronoforms5

cappleby 27 Oct, 2017
I've moved a form from Joomla to Wordpress but I get the following Fatal Error:
Uncaught Error: Class 'JHtml' not found in /home/anglicanfuture/anglicanfuture.org.au/wp-content/plugins/chronoforms/admin/chronoforms/actions/js/js.php(33) : eval()'d code:2 Stack trace: #0
The form is at anglicanfuture.org.au/register
Is there something I can add to Chronoforms5 or the Wordpress site to allow javascript to work in Wordpress?
GreyHead 27 Oct, 2017
Hi cappleby,

The problem is in Line 2 of some Custom Code you have in the form. You'll need to check that and make sure that is WordPress compatible.

Bob
cappleby 27 Oct, 2017
Answer
1 Likes
Thanks. In case others are trying to do the same thing, the Joomla version of the form has a java script element that uses a call to the Joomla library:
<?php
JHtml::_('jquery.framework');
?>
But that doesn't work in Wordpress.
Instead I needed to de-register the WP version of jquery then enqueue a new version of jQuery:
<?php
// include custom jQuery
function shapeSpace_include_custom_jquery() {
wp_deregister_script('jquery');
wp_enqueue_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array(), null, true);
}
add_action('wp_enqueue_scripts', 'shapeSpace_include_custom_jquery');
?>

jQuery(document).ready(function(jQ) {
jQ('#Fees').click(calc); ... etc.

I found this at https://digwp.com/2009/06/including-jquery-in-wordpress-the-right-way/

Chris A
cappleby 09 Mar, 2018
Further to my post, if you want to run two java scripts for some reason (which I did) the deregister and enqueue_script aren't necessary (and will give an error) so the second time you only need to begin with
<?php
// include custom jQuery
add_action('wp_enqueue_scripts',
'shapeSpace_include_custom_jquery');
?>
Of course it may be possible to include both scripts in the one java box but I haven't tried that as yet.
Chris A
This topic is locked and no more replies can be posted.