Jump to content

Recommended Posts

Posted

Ola a todos, sou novo aqui e preciso da ajuda de voces, tenho um whmcs 5.2.16 e nao consigo encontrar um script par validacao de cpf e cnpj, alguem poderia ajudar por favor, obrigado

 

testei o abaixo mas nao funciona:

"client","fieldname"=>$cfnCPF))); $cfnID = $data["id"]; foreach ($old_customfieldsarray as $cf) if (($cf["id"] == $cfnID) && ($cf["value"] != $_POST["customfield"][$cfnID])) { if (($permitirTrocaSomenteEmBranco && $cf["value"] != "") || (!$permitirTrocaSomenteEmBranco)) { $_POST["customfield"][$cfnID] = $cf["value"]; echo ""; } } } function validaCampo($vars) { global $cfnCPF,$errormessage,$tr,$permitirVazio,$permitirCPF,$permitirCNPJ; $data = mysql_fetch_array(select_query("tblcustomfields","id",array("type"=>"client","fieldname"=>$cfnCPF))); $cfnID = $data["id"]; $value = $_POST["customfield"][$cfnID]; if (!Empty($value)) { $value = SoNumeros($value); if ((strlen($value) == 11) && ($permitirCPF)) { if (!ValidaCPF($value)) $errormessage .= "
O CPF informado é inválido"; else $_POST["customfield"][$cfnID] = ValidaCPF($value); } else if ((strlen($value) == 14) && ($permitirCNPJ)) { if (!ValidaCNPJ($value)) $errormessage .= "
O CNPJ informado é inválido"; else $_POST["customfield"][$cfnID] = ValidaCNPJ($value); } else { $errormessage .= "
O valor informado no campo ".$cfnCPF." é inválido"; } } else if (!$permitirVazio) { $errormessage .= "
O campo ".$cfnCPF." é de preenchimento obrigatório"; } } function SoNumeros($num) { return ereg_replace('[^0-9]', '', $num); } function ValidaCPF($cpf) { $cpf = str_pad(ereg_replace('[^0-9]', '', $cpf), 11, '0', STR_PAD_LEFT); if (strlen($cpf) != 11 || $cpf == '00000000000' || $cpf == '99999999999') return false; for ($t = 9; $t < 11; $t++) { for ($d = 0, $c = 0; $c < $t; $c++) $d += $cpf{$c} * (($t + 1) - $c); $d = ((10 * $d) % 11) % 10; if ($cpf{$c} != $d) return false; } return substr($cpf,0,3).".".substr($cpf,3,3).".".substr($cpf,6,3)."-".substr($cpf,9,2); } function ValidaCNPJ($cnpj) { $cnpj = str_pad(ereg_replace('[^0-9]', '', $cnpj), 11, '0', STR_PAD_LEFT); if (strlen($cnpj) != 14 || $cnpj == '00000000000000' || $cnpj == '99999999999999') return false; $soma = ($cnpj[0]*5)+($cnpj[1] * 4)+($cnpj[2]*3)+($cnpj[3]*2)+($cnpj[4]*9)+($cnpj[5]*8)+($cnpj[6]*7)+($cnpj[7]*6)+($cnpj[8]*5)+($cnpj[9]*4)+($cnpj[10]*3)+($cnpj[11]*2); $d1 = ($soma % 11) < 2 ? 0 : 11 - ($soma % 11); $soma = ($cnpj[0]*6)+($cnpj[1]*5)+($cnpj[2]*4)+($cnpj[3]*3)+($cnpj[4]*2)+($cnpj[5]*9)+($cnpj[6]*8)+($cnpj[7]*7)+($cnpj[8]*6)+($cnpj[9]*5)+($cnpj[10]*4)+($cnpj[11]*3)+($cnpj[12]*2); $d2 = ($soma % 11) < 2 ? 0 : 11 - ($soma % 11); if ($cnpj[12] != $d1 || $cnpj[13] != $d2) return false; return substr($cnpj,0,2).".".substr($cnpj,2,3).".".substr($cnpj,5,3)."/".substr($cnpj,8,4)."-".substr($cnpj,12,2); } ?>

  • Administration
Posted

Dá pra ser um pouco mais específico sobre como vc usou o código?

'Cause he's my best friend, he's my pal. He's my homeboy, my rotten soldier. He's my sweet cheese. My good-time boy.

Posted

obrigdo pelo retorno

eu peguei o codigo acima crir um arquivo chamado validacpf.php mandei para a pasta hook no whmcs, acessei o admin e criei o campo personalizado com o nome cpf ou cnpj, tipo texto, validacao: $validar=TRUE ,$permitirCPF=TRUE, $permitirCNPJ=TRUE

porem mesmo o cpf valido da que nao é valido.

obrigado pela atencao.

Posted

Tem um erro na linha 24, basta acrescentar (Barra) \ antes das aspas, veja:
 

echo "<script>setTimeout(\"alert('Você não pode alterar seu CPF ou CNPJ');\",1000); </script>";

 
Eu corrigi dessa forma, e o erro de php parou mas o hook não funcionou em meu WHMCS versão 5.3.7. Esse hook ainda funciona?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

Do you agree with our terms?

-