Skip Navigation

[Resolved] How to restrict a frase or domain in Cred post form

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to restrict a frase or domain in Cred post form

Solution:
You can validate the form input using the Toolset form's hook: cred_form_validate

You can find the proposed solution in this case with the following reply:
https://toolset.com/forums/topic/how-to-restrict-a-frase-or-domain-in-cred-post-form/#post-2081363

Relevant Documentation:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

This support ticket is created 2 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 5 replies, has 2 voices.

Last updated by Tiit Sau 2 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#2081109

I'm trying to improve spam proof of public forms.
reCaptcha V2 is weak and reCaptcha V3 still not working with Tootset.
Now i try to sort out most spammers by unwanted content inserted to inputs.

#2081307

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

You can validate the form input using the Toolset form's hook: cred_form_validate
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

Does that helps?

#2081353

Hi Minesh!

I believe it helps, but can you give me a sample code for case where:
wpcf-e-mail input value contain 'mail.ru' - echo error.

#2081363

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

What if you try to use the following code.

Add it to "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/

function email_domain_validation($email){
  if (!preg_match('/^([a-z0-9\+\_\-\.]+)@([a-z0-9\+\_\-\.]{2,})(\.[a-z]{2,4})$/i', $email)) return false;
 
  $domains = array('mail.ru');
  list(, $email_domain) = explode('@', $email, 2);
  return in_array($email_domain, $domains);
}
add_filter('cred_form_validate','func_email_validation',10,2);
function func_email_validation($error_fields, $form_data){
    list($fields,$errors)=$error_fields;
    
     if ($form_data['id']==99999){
  
           $is_valid_email_domain =  email_domain_validation($_POST['wpcf-e-mail']);
           if(!$is_valid_email_domain)  {
                $errors['wpcf-e-mail']='This E-mail domain is not allowed.';
           }
     }
    return array($fields,$errors);
}

Where:
- Replace 99999 with your original form ID.

#2081431

I managed to set it up in functions.php.

Thanks!

#2081433

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.