PHP - How to fill a field using Curl?

1

What code do I use to fill fields on a web page with cURL ? These are the fields:

Field Name:

<li>
    <label for="supporter_full_name">your name*</label>
    <input class="textbox" id="supporter_full_name" name="supporter[full_name]" size="30" type="text" />
</li>

Email Address:

<li>
    <label for="supporter_email">email*</label>
    <input class="textbox" id="supporter_email" name="supporter[email]" size="30" type="text" />
</li>

Button:

<input class="large blue awesome" id="verificar_button" name="commit" type="submit" value="Verificar">

I have a list with nome and email one underneath the other, and I want to put them in textarea and have them tested, and when the value is valid >, it returns with the name and email written on the front - válido , and when the value is invalid it returns with the name and email written on the front - inválido . Thank you in advance.

    
asked by anonymous 23.07.2015 / 07:30

2 answers

1

This is very simple.

First the file structure is, according to you, ("I have a list with name and email one underneath the other"):

nome
[email protected]

Then loop the file:

// Abre o arquivo
$arquivo = file('arquivo.txt');

$linha = 0; //loop

while ($linha < count($arquivo)) {

    $nome = $arquivo[$linha]; // Primeira linha
    $email = $arquivo[$linha + 1]; // Segunda linha

    // Inicia o CURL
    $ch = curl_init();

    // Valores que deseja enviar.
    $valoresPost = [
        'supporter[full_name]' => $nome,
        'supporter[email]' => $email
    ];

    // Define as configurações do CURL:    
    curl_setopt_array($ch, [

       // Define o URL:
       CURLOPT_URL, 'http://exemplo.com',

       // Indica que é um POST:
       CURLOPT_POST => true,

       // Define a array que irá enviar (neste caso será multipart/form-data):
       CURLOPT_POSTFIELDS => $valoresPost,

       // Indica para receber os resultados:
       CURLOPT_RETURNTRANSFER => true

    ];

    // Faz a requisição (e obtem resposta):    
    $result = curl_exec($ch);

    // Obtem informações do CURL (como código HTTP):
    $info = curl_getinfo($ch);

    // Encerra o CURL:
    curl_close($ch);

    if ($info["http_code"] === 200) {

        // Sucesso

    }else{

        // Falha

    }

    $linha = $linha + 2;
}
    
08.01.2016 / 19:35
0

Bruno, you first have to join the two in an array, so you will always know that an odd number is an email and an even number is a name.

After that, you should do the validation of the data on submit and print whether the data is valid or not!

Probably validate you, or you'll have to do while starting the array items or if you create an item in the array to store the validation of them on submit!

    
23.07.2015 / 12:45