How to fill in the inputs with the information returned from a query?

-1

I'm testing the link .

It returns me after the query the following information:

array(21) { ["data_abertura"]=> string(10) "23/05/1979" ["razao_social"]=> 
string(10) "SADIA S.A." ["nome_fantasia"]=> string(8) "********" 
["cnae_principal"]=> string(8) "********" ["cnaes_secundario"]=> string(8) 
"********" ["natureza_juridica"]=> string(34) "205-4 - Sociedade Anônima 
Fechada" ["logradouro"]=> string(8) "********" ["numero"]=> string(8) 
"********" ["complemento"]=> string(8) "********" ["cep"]=> string(8) 
"********" ["bairro"]=> string(8) "********" ["cidade"]=> string(8) 
"********" ["uf"]=> string(2) "**" ["email"]=> string(27) "Delmir.Dal-
[email protected]" ["telefone"]=> string(13) "(49) 4443-000" 
["ente_federativo_responsavel"]=> string(5) "*****" ["situacao_cadastral"]=> 
string(7) "BAIXADA" ["situacao_cadastral_data"]=> string(10) "31/12/2012" 
["motivo_situacao_cadastral"]=> string(12) "INCORPORACAO" 
["situacao_especial"]=> string(8) "********" ["situacao_especial_data"]=> 
string(8) "********" }

This is the php code:

<?php

require_once '../vendor/autoload.php';

use JansenFelipe\CnpjGratis\CnpjGratis;


if(isset($_POST['captcha']) && isset($_POST['cookie']) && 
 isset($_POST['cnpj'])){
$dados = CnpjGratis::consulta($_POST['cnpj'], $_POST['captcha'], 
$_POST['cookie']);
var_dump($dados);
die;
}else
$params = CnpjGratis::getParams();
?>

<img src="data:image/png;base64,<?php echo $params['captchaBase64'] ?>" />

<form method="POST">
<input type="hidden" name="cookie" value="<?php echo $params['cookie'] ?>" 
/>

<input type="text" name="captcha" placeholder="Captcha" />
<input type="text" name="cnpj" placeholder="CNPJ" />

<button type="submit">Consultar</button>
</form>

How can I get the information and auto-fill an input with it?

    
asked by anonymous 13.05.2017 / 03:43

1 answer

1

Just use foreach . It will scan the array $dados and insert a input into each element.

<?php

require_once '../vendor/autoload.php';

use JansenFelipe\CnpjGratis\CnpjGratis;


if(isset($_POST['captcha']) && isset($_POST['cookie']) && isset($_POST['cnpj'])){
    $dados = CnpjGratis::consulta($_POST['cnpj'], $_POST['captcha'], $_POST['cookie']);

    // abaixo eu seleciono os dados e incluo em um input um por vez
    foreach($dados as $chave => $info){
?>

    <input type="text" value="<?php echo $info; ?>"/>

<?php

    } // fechamento do foreach

}else
    $params = CnpjGratis::getParams();
?>

<img src="data:image/png;base64,<?php echo $params['captchaBase64']; ?>" />

<form method="POST">
<input type="hidden" name="cookie" value="<?php echo $params['cookie']; ?>" />

<input type="text" name="captcha" placeholder="Captcha" />
<input type="text" name="cnpj" placeholder="CNPJ" />

<button type="submit">Consultar</button>
</form>
    
13.05.2017 / 05:05