Include Field Value in Validation Message

Code

Filename: gpls-use-field-value-in-validation-message.php

<?php
/**
 * Gravity Perks // Limit Submissions // Include Field Value in Validation Message
 * https://gravitywiz.com/documentation/gravity-forms-limit-submissions/
 */
// Update "123" to your form ID and "4" to your field ID. Duplicate this line and update the field ID for each field to which this should apply.
add_filter( 'gpls_field_validation_message_123_4', 'gpls_include_field_value_in_validation_message', 10, 2 );
add_filter( 'gpls_field_validation_message_123_5', 'gpls_include_field_value_in_validation_message', 10, 2 );

function gpls_include_field_value_in_validation_message( $message, $gpls_enforce ) {
	$bits = explode( '_', current_filter() );
	if ( count( $bits ) === 6 ) {
		$field_id = array_pop( $bits );
		// Update your validation message as desired.
		$message = sprintf( 'You have entered "%s" in this field before.', rgpost( "input_{$field_id}" ) );
	}
	return $message;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.