0
I have a contact form on my website, only I have a problem! When I send him, he’s redirecting to the home and I don’t want him to do that I want him to stay in the same place and I can’t figure out why he would do that.
<div class="col-md-8">
<div class="row">
<form id="contact" action="<?= $_SERVER['PHP_SELF'] ?>" method="post">
<div class="col-sm-6 form-group">
<input class="form-control" name="name" type="text" placeholder="Nome" value="<?= $name ?>">
<span class="error"><?= $name_error ?></span>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" name="email" type="text" placeholder="Email" value="<?= $email ?>">
<span class="error"><?= $email_error ?></span>
</div>
<div class="col-sm-12 form-group">
<textarea class="form-control" name="message" type="text" value="<?= $message ?>" rows="5"></textarea>
</div>
<div class="col-sm-12 form-group">
<button class="btn pull-right" name="submit" type="submit" id="contact-submit" data-submit="...Sending">Enviar</button>
</div>
<div class="success"><?= $success; ?></div>
</form>
</div>
</div>
<?= $_SERVER['PHP_SELF'] ?>
he’s not at home?– Leandro Angelo
yes you are! but the page is divided into 4 parts, and in the 4th I have the contacts where it contains the form and when I press send it goes to the top of the page and I do not want that, I want it to be in the contacts section.
– Chip
Read about Fragment of the URL.
– Woss
When submitting the form the page is reloaded, it goes to the beginning.
– Sam
and how can I make the page not be reloaded again? it is even when missing fields to fill it should remain in the same place, but not it goes also to the top of the page and then when I scroll to the form I have there the message that the fields to fill.
– Chip
For the page not to be loaded you will have to use Ajax.... for the form not to be sent with empty fields, you can use
required
or validate via Javascript.– Sam
Only that the
required
only works in HTML5, so I find it more valid to do via JS– Sam
But I already have this evaluation in Java, for example I put the name, but I do not put the email and upload to send, it goes to the top of the page and then when I scroll appears there message that the email is missing. That’s where my problem is, I want it to stay in the same place, because otherwise it feels like the email has already been sent and has not been sent, because there are still fields to fill.
– Chip
So your validation is wrong, it is allowing the sending of the form even without the fields being properly filled.
– Sam
@Chip The question is about positioning after post or form validation?
– Leandro Angelo
@Leandroangelo after the post, because he if I do not fill in the fields does not send the email, so is doing well the validation of the fields.
– Chip
@Chip you tested my suggestion?
– Leandro Angelo
@Leandroangelo yes, I had already defined this, so much so that if I click in the navigation bar in the contacts area it adds to the url /#sec_05 and if so I click in the send and it is in the contacts area, but if I don’t click the navigation bar and simply scroll when I enter the website to the contacts it doesn’t take #sec_05
– Chip