Send button in a form

0

I have a contact form on my site, but I have a problem! When I send it it is redirecting to the home and I do not want it to do that I want it to stay in the same place and I can not understand why it does it.

<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> 
    
asked by anonymous 25.04.2018 / 17:38

1 answer

0

You can add a hash to your action and an anchor in your html, so by reloading the page after the post, the scroll will be done to the form again.

In your case as the destination of the action is the same page, you could even use only the target <form id="contact" action="#contact" method="post">

<div class="col-md-8">       
   <div class="row">
      <a name="contact"></a>
      <form id="contact" action="<?= $_SERVER['PHP_SELF'] ?>#contact" 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> 
    
25.04.2018 / 18:05