How to check data after submitting form and return result in selected div?

2

I have two small problems that I have to solve to solve, let's go to the first one:

1- I have the code below right after my submit to verify that the data has been filled out:

    <?php
$data_coleta  = $_POST["data_coleta"];
$hora_coleta  = $_POST["hora_coleta"];
$unidade      = $_POST["unidade"];
$observacao   = $_POST["observacao"];
$solicitante  = $_POST["solicitante"];
$coletadora   = $_POST["coletadora"];
$erro         = 0;

// Verifica se os campos não estão em branco
if (empty($data_coleta))
  {echo "Favor inserir a Data da Coleta.<br>"; $erro=1;}
if (empty($hora_coleta))
  {echo "Favor inserir a Hora da Coleta.<br>"; $erro=1;}
if (empty($unidade))
  {echo "Favor inserir a Unidade.<br>"; $erro=1;}
if (empty($observacao))
  {echo "Favor inserir a Observação.<br>"; $erro=1;}
if (empty($solicitante))
  {echo "Favor inserir o Solicitante.<br>"; $erro=1;}
if (empty($coletadora))
  {echo "Favor inserir a Coletadora.<br>"; $erro=1;}
//Verifica se não houve erro
if($erro==0)
  {echo "<center>Todos os dados foram inseridos corretamente!</center>";
  include 'insere.php';
}
?>

The problem is that PHP is returning an error saying that the variables have no value defined, because it has not yet been submitted in the form to define the values (which is what is inserted by the user), I imagine which I then need to do an if to just do that values check after being given the submit, how to do?

I think there is something in the Bootstrap JS that I'm using that asks that when updating the page should return to the top, so I can not direct the form's action to the div that I need, JS of the button to go to the top :

<script type="text/javascript" src="js/move-top.js"></script>
    <script type="text/javascript" src="js/easing.js"></script>
    <script type="text/javascript">
    jQuery(document).ready(function($) {
        $(".scroll").click(function(event){     
            event.preventDefault();
            $('html,body').animate({scrollTop:$(this.hash).offset().top},1200);
        });
    });
</script>

     <a href="#" id="toTop" style="display: block;"><span id="toTopHover" style="opacity: 1;"></span></a>

Tips?

    
asked by anonymous 03.05.2017 / 20:50

1 answer

1

The first question has already been solved by the friend leonardopoea if (isset($_POST['submit'])) {

The second question is also very easy.

In the action of your form put the name of the destination page followed by a #support

example:

form action="index.php#support"

and on the target page put <a name="support"></a> in the exact location you want to be directed to.

More details

  

NOTE: <a name=""> specifies the name of an anchor. Not supported in HTML5

SOURCE 1 ----- #

  

Use the id attribute on an element to serve as an anchor.   Examples: <h1 id="support"></h1> <div id="support"></div> etc...

    
03.05.2017 / 21:32