Title: Loading additional scripts for CF7
Last modified: August 22, 2016

---

# Loading additional scripts for CF7

 *  [p.castaldi](https://wordpress.org/support/users/pcastaldi/)
 * (@pcastaldi)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/loading-additional-scripts-for-cf7/)
 * Hello there,
 * I would like to load additional scripts to cf7. Particularly, I have two kind
   of scripts: CondAll.js, to be loaded for every form; CondXXX.js, to be loaded
   for form XXX only if the file CondXXX is found in a certain directory.
 * I wrote down (and added to functions.php in my child theme) the following code:
 *     ```
       function wpcf7_loadConditions($wpcf7_data) {
         $formId = $wpcf7_data->id();
         if (is_null($formId) ) {return;}
   
         /* Conditions for all forms */
           wp_enqueue_script('CondAll', get_stylesheet_directory_uri() . '/js/CondAll.js', array('jquery'));
         /* END of conditions for all forms */
   
         /* Conditions for multiple forms selected by their id */
           if ( in_array($formId, array(1,2,3)) ) {
   
           }
         /*  END of conditions for multiple forms selected by their id */
   
         /* Conditions for single form based on its id */
           if ( $formId == 1 ) ) {
   
           }
         /*  END of conditions for single form based on its id */
   
         /* Conditions for forms based on the presence of a CondXXX.js file where XXX = form id */
           $myBaseURL = get_stylesheet_directory_uri() . '/js/';
           $hookName = 'Cond' . $formId;
           $condFile = $myBaseURL . $hookName . '.js';
           if (file_exists($condFile)) {
             wp_enqueue_script($hookName, $condFile, array('jquery'));
           }
         /* END of conditions for forms based on the presence of a CondXXX.js file where XXX = form id*/
   
       }
   
       add_action('wp_enqueue_scripts', 'wpcf7_loadConditions');
       ```
   
 * The code makes WP crash; what am I doing wrong?
 * [https://wordpress.org/plugins/contact-form-7/](https://wordpress.org/plugins/contact-form-7/)

Viewing 1 replies (of 1 total)

 *  Thread Starter [p.castaldi](https://wordpress.org/support/users/pcastaldi/)
 * (@pcastaldi)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/loading-additional-scripts-for-cf7/#post-5847495)
 * I noticed a couple of typos, and fixed them.
 * Now my code is:
 *     ```
       function wpcf7_loadConditions($wpcf7_data) {
         $formId = $wpcf7_data->id();
         if (is_null($formId) ) {return;}
         $myBaseURL = get_stylesheet_directory_uri() . '/js/form/';
   
         /* Conditions for all forms */
           wp_enqueue_script('CondAll', $myBaseURL . 'CondAll.js', array('jquery'));
         /* END of conditions for all forms */
   
         /* Conditions for multiple forms selected by their id */
           if ( in_array($formId, array(290,295,316,319)) ) {
           wp_enqueue_script('CondShipping', $myBaseURL . 'CondShipping.js', array('jquery'));
           }
         /*  END of conditions for multiple forms selected by their id */
   
         /* Conditions for single form based on its id */
           if ( $formId == 1 ) {
   
           }
         /*  END of conditions for single form based on its id */
   
         /* Conditions for forms based on the presence of a CondXXX.js file where XXX = form id */
           $hookName = 'Cond' . $formId;
           $condFile = $myBaseURL . $hookName . '.js';
           if (file_exists($condFile)) {
             wp_enqueue_script($hookName, $condFile, array('jquery'));
           }
         /* END of conditions for forms based on the presence of a CondXXX.js file where XXX = form id */
   
       }
   
       add_action('wp_enqueue_scripts', 'wpcf7_loadConditions');
       ```
   
 * But I only get a “Fatal error: Call to a member function id() on a non-object”
   for the line `$formId = $wpcf7_data->id();`
 * Any idea or help, anybody?

Viewing 1 replies (of 1 total)

The topic ‘Loading additional scripts for CF7’ is closed to new replies.

 * ![](https://ps.w.org/contact-form-7/assets/icon.svg?rev=2339255)
 * [Contact Form 7](https://wordpress.org/plugins/contact-form-7/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7/reviews/)

 * 1 reply
 * 1 participant
 * Last reply from: [p.castaldi](https://wordpress.org/support/users/pcastaldi/)
 * Last activity: [11 years, 3 months ago](https://wordpress.org/support/topic/loading-additional-scripts-for-cf7/#post-5847495)
 * Status: not resolved