How to get the answer to enter immediately after the question?

Asked

Viewed 399 times

0

I have a form and I want to send the questions and answers to a database. I took the question in text form and sent it to a field input Hidden and I want to put the question and the answer in the database:

<label for="pergunta">Como programar em PHP?</label>
<input type="hidden" name="pergunta[]" value="Como programar em PHP?" />
<input type="text" name="resposta[]" value="Estude na documentação do PHP.net" />

There are several questions fed by a foreach. How to iterate the questions with the answers and get something like:

How to program in PHP? Study the PHP.net documentation

I thought of something like:

$pergunta = $_POST["pergunta"]; // vai retornar um array
$resposta = $_POST["resposta"]; // vai retornar um array

foreach(){

}
  • There would be several questions and answers at the same time?

1 answer

2

Ideally you would already insert the question in the answers, like the question code, in the field for example

<input type="text" name="pergunta[idDaPergunta][resposta]" value="" />

In the controller you will pick up

$this->input->post("pergunta");

Already brings you all the question and answer data (s).

  • Interesting that!!! I will take a look at it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.