How to write data without the Jquery masquerade using Cakephp3

0

I have a system in CakePHP 3.4.5 and I am using jquery to apply mask in the fields cep, cpf, cnpj and etc.
How do I save the data without the mask?
I call Jquery in my default.ctp which is in my layout folder.

echo $this->Html->script('jquery.maskedinput.min');

I also put the mask information code below.

echo $this->Html->scriptBlock('jQuery(function($){ $("#cpf").mask("999.999.999-99"); });', array('inline' => false));
echo $this->Html->scriptBlock('jQuery(function($){ $("#cep").mask("99999-999"); });', array('inline' => false));

Thankful

    
asked by anonymous 29.05.2017 / 19:36

2 answers

1

The way to make mask via PHP, pick up the clean number, example 12345678910 and turn it into 123.456.789-10 would be with the code below:

$cpf = "12345675910";
echo $cpfMask = substr($cpf, 0, 3) . "." . substr($cpf, 3,3) .  "." . substr($cpf, 6,3) . "-" . substr($cpf, 9);
    
30.05.2017 / 16:07
1

You can remove what you do not want on the backend. Where you reset the data, clear the variable before saving. Example:

<?php

// Remove qualquer caracter diferente de número
// Antes 123.456.789-10
$cpf = preg_replace("/\D/i", "", $cpf);
// Depois 12345678910

?>
    
29.05.2017 / 20:31