Last active
October 16, 2023 23:56
-
-
Save estevan-ulian/18abd00b915aff2d7417048e436ec776 to your computer and use it in GitHub Desktop.
Este hook mapeia os campos de input que possuem a classe 'cpf' e 'cnpj' e remove todos os caracteres não numéricos antes do momento da submissão do formulário Gravity Forms..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'gform_pre_submission', 'pre_submission_handler' ); | |
function pre_submission_handler( $form ) { | |
foreach ( $form['fields'] as &$field ) { | |
if ( $field->cssClass == 'cpf' || $field->cssClass == 'cnpj' ) { | |
// Obtém o valor do campo do formulário | |
$field_value = rgpost( "input_{$field->id}" ); | |
// Remove todos os caracteres não numéricos | |
$cleaned_value = preg_replace( '/[^0-9]/', '', $field_value ); | |
// Atualiza o valor do campo no formulário | |
$_POST[ "input_{$field->id}" ] = $cleaned_value; | |
} | |
} | |
return $form; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment