2
Hello, I have a javascript function that adds fields in my form. And I want to save the values of these fields in my database. The field code is these.
<div><input type="radio" name="opcao2" value="Mae"/><label>Mae</label>
<input type="radio" name="opcao2" value="Pai"/><label>Pai</label>
<input type="radio" name="opcao2" value="Madrasta"/><label>Madrastra</label>
<input type="radio" name="opcao2" value="Padrastro"/><label>Padrastro</label>
<input type="radio" name="opcao2" value="Avó"/><label>Avó</label>
<input type="radio" name="opcao2" value="Avô"/><label>Avô</label>
<input type="radio" name="opcao2" value=""/><label>Outro</label>
<input type="text" name="opcao2" />
</br>
<label>Nome:</label>
<input type='text' name='nome_resp'/>
<label>RG:</label>
<input type="text" name="rg_resp"/>
<label>CPF:</label>
<input type="text" name="cpf_resp"/>
<label>Telefone:</label>
<input type="text" name="telefone_resp"/>
<label>Celular:</label>
<input type="text" name="celular_resp"/>
<label>E-mail</label>
<input type="text" name="email_resp"/></div>
My PHP looked like this:
$respon = new Responsavel($db);
$respon->id_aluno = $_POST['rg'];//gravar com RG
$respon->parente1 = $_POST['opcao2'];
$respon->nome1 = $_POST['nome_resp'];
$respon->rg1 = $_POST['rg_resp'];
$respon->cpf1 = $_POST['cpf_resp'];
$respon->telefone1 = $_POST['telefone_resp'];
$respon->celular1 = $_POST['celular_resp'];
$respon->email1 = $_POST['email_resp'];
if($respon->criar()){
echo "<script>alert ('Gravado com sucesso')</script>";
}
What problem are you facing? Error Message? What is not working?
– Marco Aurélio Deleu
Apparently there is no error, if there is in the class, which was not posted.
– Inkeliz
So at the time I fill in the registration I choose how many fields I want to add. Only if I declare all variables in the php part it appears an error because I may or may not add these fields to more.
– Arthur Balmanto
The problem is the
criar()
.– rray
So if I leave only these fields with this php ok it works. the problem and when I add more fields.
– Arthur Balmanto
Voce is passing the data via get or post?
– RFL
Put the class
Responsavel
here too, for sure the error is in it. And where therg
? Since the form has no input with such name– Leonardo
I am passing the data via POST. So the part of the form where you have the rg exists only no posted. And the class is also correct I just need to know how I record multiple data when I add more fields. NOTE: I ended up not showing, but just below my last input there is a button that adds (or clon) these previous fields.
– Arthur Balmanto
@Arthurbalmanto In javascript, try to generate a json of the added fields, and make the Submit of the form data using AJAX. In php, use the json_decode() function to manipulate this information.
– André Ramos
@Andrera ok, thank you I’ll try here.
– Arthur Balmanto