Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

138
Visualizações
How to insert input value into array data php?

I created a form like this, How should I do so that the value of the form field is entered into the php data array?

Expected that the value of the submitted data is entered into this line:

$customer_details = array(
  'first_name'    => "value input first_name",
  'email'         => "value input email",
  'phone'         => "value input phone"
);

form input:

<form>
  <label>Name:</label>      
  <input name="first_name" type="text" maxlength="50"><br>
  <label>Phone:</label> 
  <input name="phone" type="text" maxlength="100"><br>
  <label>Email:</label> 
  <input name="email" type="text" maxlength="100"><br><br>
  <button id="pay-button">Pay!</button>
</form>

The php code and html form are in 1 file.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Your form needs 2 attributes (action, method) and your button needs 1 (type) :

<form action="#" method="GET">
  <label>Name:</label>      
  <input name="first_name" type="text" maxlength="50"><br>
  <label>Phone:</label> 
  <input name="phone" type="text" maxlength="100"><br>
  <label>Email:</label> 
  <input name="email" type="text" maxlength="100"><br><br>
  <button type="submit" id="pay-button">Pay!</button>
</form>

So the submit button will handle the form using the same page.

You can check if the form is handled using this :

if(isset($_GET['name'])) {
    //use your form
}

Then you have an existing array $_GET. You can access your datas using the name of your input (ex : $_GET['first_name']).

If you want to use your $customer_array, then :

$customer_details = array(
  'first_name'    => $_GET['first_name'],
  'email'         => $_GET['email'],
  'phone'         => $_GET['phone']
);

UPDATED

The final result should be :

if(isset($_GET['name'])) {
    
    $customer_details = array(
      'first_name'    => $_GET['first_name'],
      'email'         => $_GET['email'],
      'phone'         => $_GET['phone']
    );

    //Any other treatment...

} else {

  <form action="#" method="GET">
    <label>Name:</label>      
    <input name="first_name" type="text" maxlength="50"><br>
    <label>Phone:</label> 
    <input name="phone" type="text" maxlength="100"><br>
    <label>Email:</label> 
    <input name="email" type="text" maxlength="100"><br><br>
    <button type="submit" id="pay-button">Pay!</button>
  </form>

}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda