PHP Classes

File: cnpj.php

Recommend this page to a friend!
  Classes of Pablo Veinberg   PHP Validar CPF e CNPJ   cnpj.php   Download  
File: cnpj.php
Role: Example script
Content type: text/plain
Description: CNPJ Test Example
Class: PHP Validar CPF e CNPJ
Validate Brazil fiscal numbers
Author: By
Last change:
Date: 9 years ago
Size: 1,659 bytes
 

Contents

Class file image Download
<!DOCTYPE html>

<html>
    <head>
        <title>Validador de CNPJ</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width">
        <link href="./css/style.css" rel="stylesheet"/>
    </head>
    <body>
        <div id="content">

            <h2>Validar CNPJ</h2>
            <div>
                <form method="POST">
                    <label>
                        Ingresse o CNPJ (Apenas números):
                    </label>
                    <input type="text" name="cnpj" maxlength="14"/>
                    <input type="submit" value="Validar"/>
                </form>
            </div>
            <?php if (!is_null($_POST) && !empty($_POST['cnpj'])): ?>
<div>

                    <?php
                    $cnpj
= $_POST['cnpj'];
                    unset(
$_POST);

                    require_once
'./classes/ValidarChaveFiscal.php';
                   
$validador = new ValidarChaveFiscal($cnpj, 'CNPJ');
                    if (
$validador->isValido()) {
                        echo
"<p class='valido'>O CNPJ {$validador->getChaveFormatada()} é válido.</p>";
                    } else {
                        echo
"<p class='erro'>O CNPJ {$validador->getChaveFormatada()} não é válido.</p>";
                        foreach (
$validador->getErros() as $erro) {
                            echo
"<li class='erro'>{$erro}</li>";
                        }
                    }
                   
?>
</div>
            <?php endif; ?>

            <p><a href="./">Voltar</a></p>
        </div>
    </body>
</html>