Skip to content

Instantly share code, notes, and snippets.

@LeoLopesWeb
Last active February 13, 2023 19:26
Show Gist options
  • Select an option

  • Save LeoLopesWeb/412495259a37a495f4a4a5889142f63f to your computer and use it in GitHub Desktop.

Select an option

Save LeoLopesWeb/412495259a37a495f4a4a5889142f63f to your computer and use it in GitHub Desktop.
// testa se o campo CPF (Contact form 7) já existe no banco de dados na tabela 'wp_cf7_vdata_entry' (plugin: Advanced Contact form 7 DB)
add_filter( 'wpcf7_validate_text', 'alphanumeric_validation_filter', 20, 2 );
add_filter( 'wpcf7_validate_text*', 'alphanumeric_validation_filter', 20, 2 );
function alphanumeric_validation_filter( $result, $tag ) {
$tag = new WPCF7_Shortcode( $tag );
if ( 'your-cpf' == $tag->name ) {
$cpf = $_POST['your-cpf'];
global $wpdb;
$count = $wpdb->get_var("SELECT COUNT(*) FROM wp_cf7_vdata_entry WHERE value = '$cpf'");
if ( $count ) {
$result->invalidate( $tag, "Esse CPF não pode ser cadastrado novamente" );
}
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment