slaFFik
8/29/2017 - 8:55 AM

WPForms: Change the JS validation strings based on a form ID (useful for multi-language sites)

WPForms: Change the JS validation strings based on a form ID (useful for multi-language sites)

<?php

add_filter( 'wpforms_frontend_strings', function( $strings ) {
	global $post;

	if ( ! isset( $post->post_content ) ) {
		return $strings;
	}

	preg_match( '~\[wpforms id=\"(\d+)\"~', $post->post_content, $matches );

	if ( ! is_array( $matches ) || ! isset( $matches[1] ) ) {
		return $strings;
	}

	$form_id = (int) $matches[1];

	// This form ID should be changed and the text below it as well.
	if ( 181 === $form_id ) {
		$strings['val_required'] = 'PUT HERE YOUR CUSTOM TEXT';
	}

	return $strings;
} );