Home Forums General Issues How to add a function to a text field?


How to add a function to a text field?

  • I am using this code to add a validation of the letter of the Spanish D.N.I, but I don’t know why it doesn’t work for me. In case someone can help me.

    add_action('acf/render_field_settings/type=textarea', 'validar_dni');
    function validar_dni($dni){
     $letra = substr($dni, -1);
    	$numeros = substr($dni, 0, -1);
    	if ( substr("TRWAGMYFPDXBNJZSQVHLCKE", $numeros%23, 1) == $letra && strlen($letra) == 1 && strlen ($numeros) == 8 ){
    		echo 'valido';
    		echo 'no valido';
  • acf/render_field_settings is used to add settings and not to perform an operation.

    What is it you’re trying to achive? If you are attempting to validate a value then you need to use the acf/validate_value filter.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.