Error sending form when pressing Enter - PHP

0

Good evening. I'm having a problem submitting a form, typing Enter returns the error: "Undefined Index" from php. However, if I click the Log in button, it submits normally.

< script type = "text/javascript" >
  $(function() {
    $('.form').form({
      fields: {
        usuario: {
          identifier: 'usuario',
          rules: [{
            type: 'empty',
            prompt: 'Preencha o campo Usuário!'
          }]
        },

        senha: {
          identifier: 'senha',
          rules: [{
            type: 'empty',
            prompt: 'Preencha o campo Senha!'
          }]
        }
      }
    });
  }); <
/script>
* {
  margin: 0px;
  padding: 0px;
  border: none;
  outline: none !important;
}

body {
  background-color: #f4f4f4 !important;
}

.login-alerts {
  width: 350;
  height: 50px;
  margin: 0 auto;
}

.login-center {
  width: 350px;
  height: auto;
  background-color: #ffffff;
  margin: 0 auto;
  margin-top: 8%;
  box-shadow: 1px 2px 8px 1px #d6d6d6;
  border-radius: 6px;
}

.login-logo {
  padding: 20px 0px 0px 20px;
}

.login {
  padding: 10px 20px 20px 20px;
}
<link href="https://raw.githubusercontent.com/Semantic-Org/Semantic-UI/master/dist/semantic.min.css" rel="stylesheet" />
<script src="https://raw.githubusercontent.com/Semantic-Org/Semantic-UI/master/dist/semantic.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>


<body>
  <div class="login-center">
    <div class="login-top">
      <div class="login-logo"><img src="assets/img/sigio-logo.svg" width="150"></div>
    </div>

    <div class="login">
      <form class="ui form error" action="" method="POST">
        <div class="field ui fluid left icon input">
          <input type="text" placeholder="Usuário" id="usuario" name="usuario" maxlength="15">
          <i class="user icon"></i>
        </div>

        <div class="field ui fluid left icon input">
          <input type="password" placeholder="Senha" id="senha" name="senha" maxlength="25">
          <i class="lock icon"></i>
        </div>

        <div class="field">
          <input type="submit" class="fluid ui primary button" name="logar" value="Logar">
        </div>

        <div class="ui error message"></div>
      </form>
    </div>
  </div>
</body>

</html>
    
asked by anonymous 23.12.2018 / 03:18

1 answer

0

Following what the message says, some variable with the name "log" has not been defined.

Try using something like:

if( isset($_POST['logar']) ){
   // Seu código
}

This will cause the "log" field to be checked and the "notice" message will not be displayed because of this. When the existence of the same is not verified and the PHP interpreter issues the E_NOTICE .

Another alternative would be to put a @ before starting in the variable name, as follows:

@$logar = $_POST['logar'];
//ou
$logar = @$_POST['logar'];

However, it is not recommended that this be done because hiding errors of type E_NOTICE is mostly gambiarra. What you should do is surround all possible errors by generating personalized messages.

That's why this existence check was necessary.

And to finish, you do not need to set a value for the button that sends the form data.

Button name setting is enough.

<input type="submit" class="fluid ui primary button" name="logar">
    
23.12.2018 / 12:29