4
I have a PHP form. When I give Submit it should take the values coming for $_POST. But it turns out that the returned data comes only value 1.
I don’t know what’s going on. Everything seems normal. :/
<form method="POST" action="">
<input type="hidden" name="action" value="cadastrar_studante">
<div class="row mt20">
<div class="col-xs-6">
<div class="form-group">
<label class="control-label" for="name-student-form">Nome</label>
<input type="text" class="form-control" name="name-student-form" id="name-student-form">
</div>
</div>
<div class="col-xs-6">
<div class="form-group">
<label class="control-label" for="email-student-form">Email</label>
<input type="email" class="form-control" name="email-student-form" id="email-student-form">
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<button type="submit" class="btn btn-primary pull-right">Cadastrar</button>
</div>
</div>
</form>
Here’s PHP. I got the data for $_POST. I’m using PHP PDO.
if( in_array("cadastrar_studante", $_POST) ) {
$name_student = isset( $_POST['name-student-form'] );
$email_student = isset( $_POST['email-student-form'] );
//echo $name_student . " <--> " . $email_student;
$students->set_name_student( $name_student );
$students->set_email_student( $email_student );
/** Inserir aluno */
if( $students->insert() ) {
$echo = <<<MSG
<script type="text/javascript">
jQuery(document).ready(function($)) {
$("#modal-feedback").find(".modal-body").html("Aluno cadastrado com sucesso.");
$("#modal-feedback").modal("show");
}
</script>
MSG;
echo $echo;
}
}
Another detail, can be the tags inputs without closing.
– flpms
Tags
<input>
don’t need to close.– Gustavo Rodrigues
Could you show the PHP code? It doesn’t seem to be a problem in HTML.
– Gustavo Rodrigues
Problem with the
<form>
Not closed is not: I tested in three browsers and all returned the data correctly. While testing I thought of a possibility: is there any script interfering?– Gustavo Rodrigues
No Ustavo, it is closed, just forgot to put here. : / Like this, I’m doing the CRUD on the same page. So I’m taking the form action to make such a change in the bank.
– Randson
Now that you have posted the PHP code we found the error, a little too late for me, but the problem has been solved. The test closed or was no longer by Rafael and flpms, and because I never close tags that don’t need to be closed.
– Gustavo Rodrigues
But thank you Gustavo. It was very helpful. :)
– Randson