Title: $(&#8230;).wpcf7InitForm() is not a function
Last modified: June 6, 2017

---

# $(…).wpcf7InitForm() is not a function

 *  Resolved [Rasso Hilber](https://wordpress.org/support/users/nonverbla/)
 * (@nonverbla)
 * [8 years, 12 months ago](https://wordpress.org/support/topic/wpcf7initform-is-not-a-function/)
 * Hi there,
 * with the newest release and the drop of jquery.forms, the function `wpcf7InitForm()`
   is not longer available. I have been using this function for my ajax-driven site
   to re-initialize CF7 for new forms on each ajax page load. Is there another (
   new) way to initialize CF7 on the fly?
 * best
    Rasso

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Thread Starter [Rasso Hilber](https://wordpress.org/support/users/nonverbla/)
 * (@nonverbla)
 * [8 years, 12 months ago](https://wordpress.org/support/topic/wpcf7initform-is-not-a-function/#post-9201324)
 * so… one solution could be to wrap the whole first self-invoked function into 
   a wpcf7.init() function:
 *     ```
       wpcf7.init = function() {
   
       	$( function() {
       		wpcf7.supportHtml5 = ( function() {
       			var features = {};
       			var input = document.createElement( 'input' );
   
       			features.placeholder = 'placeholder' in input;
   
       			var inputTypes = [ 'email', 'url', 'tel', 'number', 'range', 'date' ];
   
       			$.each( inputTypes, function( index, value ) {
       				input.setAttribute( 'type', value );
       				features[ value ] = input.type !== 'text';
       			} );
   
       			return features;
       		} )();
   
       		$( 'div.wpcf7 > form' ).each( function() {
       			var $form = $( this );
   
       			$form.submit( function( event ) {
       				if ( typeof window.FormData !== 'function' ) {
       					return;
       				}
   
       				wpcf7.submit( $form );
       				event.preventDefault();
       			} );
   
       			$( '.wpcf7-submit', $form ).after( '<span class="ajax-loader"></span>' );
   
       			wpcf7.toggleSubmit( $form );
   
       			$form.on( 'click', '.wpcf7-acceptance', function() {
       				wpcf7.toggleSubmit( $form );
       			} );
   
       			// Exclusive Checkbox
       			$( '.wpcf7-exclusive-checkbox', $form ).on( 'click', 'input:checkbox', function() {
       				var name = $( this ).attr( 'name' );
       				$form.find( 'input:checkbox[name="' + name + '"]' ).not( this ).prop( 'checked', false );
       			} );
   
       			// Free Text Option for Checkboxes and Radio Buttons
       			$( '.wpcf7-list-item.has-free-text', $form ).each( function() {
       				var $freetext = $( ':input.wpcf7-free-text', this );
       				var $wrap = $( this ).closest( '.wpcf7-form-control' );
   
       				if ( $( ':checkbox, :radio', this ).is( ':checked' ) ) {
       					$freetext.prop( 'disabled', false );
       				} else {
       					$freetext.prop( 'disabled', true );
       				}
   
       				$wrap.on( 'change', ':checkbox, :radio', function() {
       					var $cb = $( '.has-free-text', $wrap ).find( ':checkbox, :radio' );
   
       					if ( $cb.is( ':checked' ) ) {
       						$freetext.prop( 'disabled', false ).focus();
       					} else {
       						$freetext.prop( 'disabled', true );
       					}
       				} );
       			} );
   
       			// Placeholder Fallback
       			if ( ! wpcf7.supportHtml5.placeholder ) {
       				$( '[placeholder]', $form ).each( function() {
       					$( this ).val( $( this ).attr( 'placeholder' ) );
       					$( this ).addClass( 'placeheld' );
   
       					$( this ).focus( function() {
       						if ( $( this ).hasClass( 'placeheld' ) ) {
       							$( this ).val( '' ).removeClass( 'placeheld' );
       						}
       					} );
   
       					$( this ).blur( function() {
       						if ( '' === $( this ).val() ) {
       							$( this ).val( $( this ).attr( 'placeholder' ) );
       							$( this ).addClass( 'placeheld' );
       						}
       					} );
       				} );
       			}
   
       			if ( wpcf7.jqueryUi && ! wpcf7.supportHtml5.date ) {
       				$form.find( 'input.wpcf7-date[type="date"]' ).each( function() {
       					$( this ).datepicker( {
       						dateFormat: 'yy-mm-dd',
       						minDate: new Date( $( this ).attr( 'min' ) ),
       						maxDate: new Date( $( this ).attr( 'max' ) )
       					} );
       				} );
       			}
   
       			if ( wpcf7.jqueryUi && ! wpcf7.supportHtml5.number ) {
       				$form.find( 'input.wpcf7-number[type="number"]' ).each( function() {
       					$( this ).spinner( {
       						min: $( this ).attr( 'min' ),
       						max: $( this ).attr( 'max' ),
       						step: $( this ).attr( 'step' )
       					} );
       				} );
       			}
   
       			// Character Count
       			$( '.wpcf7-character-count', $form ).each( function() {
       				var $count = $( this );
       				var name = $count.attr( 'data-target-name' );
       				var down = $count.hasClass( 'down' );
       				var starting = parseInt( $count.attr( 'data-starting-value' ), 10 );
       				var maximum = parseInt( $count.attr( 'data-maximum-value' ), 10 );
       				var minimum = parseInt( $count.attr( 'data-minimum-value' ), 10 );
   
       				var updateCount = function( target ) {
       					var $target = $( target );
       					var length = $target.val().length;
       					var count = down ? starting - length : length;
       					$count.attr( 'data-current-value', count );
       					$count.text( count );
   
       					if ( maximum && maximum < length ) {
       						$count.addClass( 'too-long' );
       					} else {
       						$count.removeClass( 'too-long' );
       					}
   
       					if ( minimum && length < minimum ) {
       						$count.addClass( 'too-short' );
       					} else {
       						$count.removeClass( 'too-short' );
       					}
       				};
   
       				$( ':input[name="' + name + '"]', $form ).each( function() {
       					updateCount( this );
   
       					$( this ).keyup( function() {
       						updateCount( this );
       					} );
       				} );
       			} );
   
       			$form.on( 'change', '.wpcf7-validates-as-url', function() {
       				var val = $.trim( $( this ).val() );
   
       				// check the scheme part
       				if ( val && ! val.match( /^[a-z][a-z0-9.+-]*:/i ) ) {
       					val = val.replace( /^\/+/, '' );
       					val = 'http://' + val;
       				}
   
       				$( this ).val( val );
       			} );
   
       			if ( wpcf7.cached ) {
       				wpcf7.refill( $form );
       			}
       		} );
       	} );
   
       }
   
       wpcf7.init();
       ```
   
 * Then later, I can call this from my own code:
 *     ```
       if( typeof wpcf7 === 'object' && typeof wpcf7.init === 'function' ) {
         wpcf7.init();
       }
       ```
   
 *  [konsument](https://wordpress.org/support/users/konsument/)
 * (@konsument)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/wpcf7initform-is-not-a-function/#post-9223702)
 * Hi,
    Im facing the same problem ony many sites. Could you pls explain where you
   put the code in?
 *  Thread Starter [Rasso Hilber](https://wordpress.org/support/users/nonverbla/)
 * (@nonverbla)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/wpcf7initform-is-not-a-function/#post-9228963)
 * [@konsument](https://wordpress.org/support/users/konsument/), I uploaded the 
   full rewritten scripts.js file to my server, you can download it from there and
   replace the file /plugins/contact-form-7/includes/js/scripts.js with my version:
 * [http://test.rassohilber.com/wpcf7/scripts.js](http://test.rassohilber.com/wpcf7/scripts.js)
 *  [konsument](https://wordpress.org/support/users/konsument/)
 * (@konsument)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/wpcf7initform-is-not-a-function/#post-9249606)
 * many thanks. Meanwhile Ive found a much [easier solution](https://wordpress.org/support/topic/init-function-wpcf7initform/).
 *  [topitoconnectey](https://wordpress.org/support/users/topitoconnectey/)
 * (@topitoconnectey)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/wpcf7initform-is-not-a-function/#post-9360309)
 * Here’s the best way :
 *  `function initContactForm() {
    $( ‘div.wpcf7 > form’ ).each( function() { var
   $form = $( this ); wpcf7.initForm( $form );
 *  if ( wpcf7.cached ) {
    wpcf7.refill( $form ); } } );
 *  }`
 *  [azizultex](https://wordpress.org/support/users/azizultex/)
 * (@azizultex)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/wpcf7initform-is-not-a-function/#post-9800078)
 * Thanks [@topitoconnectey](https://wordpress.org/support/users/topitoconnectey/)
 *  [cornhustlah](https://wordpress.org/support/users/cornhustlah/)
 * (@cornhustlah)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/wpcf7initform-is-not-a-function/#post-9873139)
 * thank you, [@topitoconnectey](https://wordpress.org/support/users/topitoconnectey/)
 * looks like i was incorrectly told to use `$form.wpcf7InitForm()` when it’s really`
   wpcf7.initForm( $form )`
 * did this function change in recent times, though? because it seems like `wpcf7InitForm()`
   was once the correct function…?

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘$(…).wpcf7InitForm() is not a function’ 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/)

 * 7 replies
 * 5 participants
 * Last reply from: [cornhustlah](https://wordpress.org/support/users/cornhustlah/)
 * Last activity: [8 years, 4 months ago](https://wordpress.org/support/topic/wpcf7initform-is-not-a-function/#post-9873139)
 * Status: resolved