• Resolved Candlelite

    (@candlelite)


    We are getting a lot of SPAM where the first name (name-1) and second name (name-2) fields have the same content. I have tried “don’t send” email if name-1 contains name-2 and name-1 is name-2 but these operators do not work for this test. Is there any way of adding name-1 equals name-2 don’t send. If not could this operator be developed – it would be a great filter.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @candlelite

    I hope you’re well today and thank you for your question!

    Currently there is no conditional logic support for comparing two or more fields yet. You can compare field against some value but not against another field value. This is something that we do plan to add to the plugin in future but I don’t have ETA.

    For now, you can use this additional code snippet to achieve this:

    <?php 
    
    add_filter( 'forminator_custom_form_submit_errors', 'compare_fields_submission_filter', 99, 3 );
    function compare_fields_submission_filter( $submit_errors, $form_id, $field_data_array ) {
    	
    	
    	$forms = array( 3010 ); // IDs of forms to check; if more than one, separate by comma 
    	$field_a = 'name-1';
    	$field_b = 'name-2';
    	
    	$error_msg = 'Incorrect values!';
    	
    	// DON'T EDIT BELOW
    	
    	
    	if ( !in_array( $form_id, $forms ) ) {
    		return $submit_errors;
    	}
    	
    	$field_a_value = '';
    	$field_b_value ='';
    	
    	foreach( $field_data_array as $arr ) {
    		
    		if ( $arr['name'] == $field_a ) $field_a_value = $arr['value'];
    		if ( $arr['name'] == $field_b ) $field_b_value = $arr['value'];
    		
    	}
    	
    	if ( ( !empty( $field_a_value) ) && ( !empty( $field_b_value) ) ) {
    		
    		if ( $field_a_value === $field_b_value ) { 
    		
    			$submit_errors[][$field_b] = $error_msg;
    		
    		}
    		
    	}
    	
    
    	return $submit_errors;
    }

    You’d need to add it to the site as MU plugin:

    – create an empty file with a .php extension (e.g. “forminator-compare-fields-filter.php”) in the “/wp-content/mu-plugins” folder of your site’s WordPress install on the server

    – copy and paste code into it and save it.

    You’ll also need to adjust these four lines in the code:

    $forms = array( 3010 ); 
    $field_a = 'name-1';
    $field_b = 'name-2';
    $error_msg = 'Incorrect values!';

    where accordingly:

    – in first, replace the 3010 number with your form ID (form ID is the number you see in form shortcode)

    – in second and third – adjust fields’ IDs if necessary

    – in fourth you can set your own error message.

    Best regards,
    Adam

    Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @candlelite

    We haven’t heard from you in a while, I’ll go and mark this thread as resolved. If you have any additional questions or require further help, please let us know!

    Kind Regards,
    Kris

    Thread Starter Candlelite

    (@candlelite)

    Kris

    Many thanks for this code – works a treat. I usually try to avoid custome code on websites because of the issues of support. I have tried other forms of captcaha but still the SPAM gets through. I guess this solution will work for a while until SPAMmers realise that their code needs updating!

    • This reply was modified 9 months, 1 week ago by Candlelite.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘SPAM filter’ is closed to new replies.