Buy Now
Sign in

Using javascript in Wordpress Chronoforms5

cappleby , October 27 2017
Answered
C
cappleby
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
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
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
C
cappleby
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
C
cappleby
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