0

It is a login form:


<form action="login.php" method="post">
  <div class="input-field">
      <input type="text" name="email" placeholder="Email">
      <i class="fa-solid fa-envelope icon"></i>
  </div>

  <div class="input-field">
      <input type="password" name="password" id="password" placeholder="Password">
      <i class="fa-solid fa-lock icon"></i>
      <i class="fa-solid fa-eye-slash showHidePw ic" id="togglePassword" onclick="showIcon()" style="display: block"></i>
      <i class="fa-solid fa-eye showHidePw ic" id="eye" style="display:none" onclick="showIcon()"></i>
  </div>

  <div class="checkbox-text">
      <div class="checkbox-content">
          <input type="checkbox" id="logCheck">
          <label for="logCheck" class="text">Remember me</label>
      </div>

      <a href="#" class="text">Forgot password?</a>
  </div>

  <div class="input-field button">
      <input type="submit" name="login-btn" value="Login">
  </div>
</form>

PHP code:


if (isset($_POST['login-btn'])) {
  dd($_POST);
}

The input submit does not work. When I click onto the button, nothing happens. I do not need to show you the real code, because also like this, it doesn't show anything. It is weird because the structure is the same of the the signup form, which, instead, works...

I hope someone can help me. Thanks

Edit:

this is the signup form (and the whole php code):

<form action="signup.php" method="post">
  <div class="input-field signup">
      <input type="text" value="<?php echo $name; ?>" placeholder="Name" name="name">
      <i class="fa-solid fa-user icon"></i>
  </div>
  <div class="input-field signup">
      <input type="text" value="<?php echo $lastname; ?>" placeholder="Last Name" name="lastname">
      <i class="fa-solid fa-user icon"></i>
  </div>
  <div class="input-field signup">
      <input type="text" value="<?php echo $email; ?>" placeholder="Email" name="email">
      <i class="fa-solid fa-envelope icon"></i>
  </div>
  <div class="input-field signup">
      <input type="password" value="<?php echo $password; ?>" class="password" name="password" placeholder="Password" id="password">
      <i class="fa-solid fa-lock icon"></i>
  </div>
  <div class="input-field signup">
      <input type="password" value="<?php echo $passwordConf; ?>" id="password" name="passwordConf" placeholder="Repeat Password">
      <i class="fa-solid fa-lock icon"></i>
  </div>


  <div class="input-field button signup">
      <input type="submit" name="register-btn" value="Sign Up">
  </div>
</form>

PHP:

<?php

include(ROOT_PATH . "/app/database/db.php");
include(ROOT_PATH . "/app/helpers/validateUser.php");

$errors = array();
$name = '';
$lastname = '';
$email = '';
$password = '';
$passwordConf = '';

if (isset($_POST['register-btn'])) {
    $errors = validateUser($_POST);

    if (count($errors) === 0) {
        unset($_POST['register-btn'], $_POST['passwordConf']);
        $_POST['admin'] = 0;

        $_POST['password'] = password_hash($_POST['password'], PASSWORD_DEFAULT);

        $user_id = create('users', $_POST);
        $user = selectOne('users', ['id' => $user_id]);

        // log user in
        $_SESSION['id'] = $user['id'];
        $_SESSION['name'] = $user['name'];
        $_SESSION['admin'] = $user['admin'];
        $_SESSION['message'] = 'Login successful!';
        $_SESSION['type'] = 'success';

        if ($_SESSION['admin']) {
            header('location: ' . BASE_URL . 'admin/dashboard.php');
        } else {
            header('location: ' . BASE_URL . '/index.php');
        }
        exit();
    } else {
        $name = $_POST['name'];
        $lastname = $_POST['lastname'];
        $email = $_POST['email'];
        $password = $_POST['password'];
        $passwordConf = $_POST['passwordConf'];
    }


}


if (isset($_POST['login-btn'])) {
  dd($_POST);
}
Rob
  • 14,746
  • 28
  • 47
  • 65
GiuRos
  • 11
  • 1
  • What does `$_SERVER['REQUEST_METHOD']` say's? – Kip Apr 30 '22 at 19:44
  • From my code ```

    ```. I can't reproduce.
    – vee Apr 30 '22 at 19:46
  • [This](https://stackoverflow.com/questions/38996725/why-does-a-html-form-not-send-with-the-name-submit-and-type-submit-using-jqu), [and this](https://stackoverflow.com/questions/25009128/jquery-form-submit-not-sending-post) maybe your problem if you use JS to submit the form. – vee Apr 30 '22 at 19:47
  • I am not using JS @vee. I use the same as the signup button, but signup works, login does not respond... – GiuRos Apr 30 '22 at 19:50
  • Both form are working fine for me. – vee Apr 30 '22 at 19:59
  • @Kip I am new to PHP... where should I write that line of code? – GiuRos Apr 30 '22 at 20:00
  • `if (isset($_POST['login-btn'])) { echo $_SERVER['REQUEST_METHOD']; }` – Kip Apr 30 '22 at 20:02
  • @vee ok... what can be the reason why login is not working and signup does? Thank you very much :) – GiuRos Apr 30 '22 at 20:03
  • 2 Possible reason. 1. There is a JS somewhere that is listening to form submit event and prevent it. Maybe event delegation from somewhere. You can check that form is really submit to server via web browser network inspector. 2. There is one or more PHP errors and you did not show the error. If there is fatal error and php.ini did not show the errors, the server will be response as white page. – vee Apr 30 '22 at 20:06
  • @Kip it does nothing... When I click on the input nothing happens. What php code is written is not relevant unfortunately, since there is something that block that code to run – GiuRos Apr 30 '22 at 20:07
  • 1
    Note that your `if (isset($_POST['register-btn']))` and `if (isset($_POST['login-btn']))` is on the same file? But your form point the action to different files. – vee Apr 30 '22 at 20:09
  • Have you removed everything between `if (isset($_POST['login-btn'])) { }` only the request method left, when you tried it?? – Kip Apr 30 '22 at 20:10
  • 1
    @vee should they be on different files? I have created another file... But I think the problem is not in the php: the form does not respond to any command. Or maybe it does depend on php. Idk – GiuRos Apr 30 '22 at 20:29
  • If you are using `dd()` then you are using a framework, that may be useful info in your tag list, because none of your other code appears to be using that framework – RiggsFolly Apr 30 '22 at 20:50
  • @RiggsFolly `dd()` stands for dump and die. It's a self made function for `vardump()` and `die()`. @GiuRos you use `action="login.php"` so the `if (isset($_POST['login-btn'])) { }` if login code needs to be in the login.php file. Or you need to change the `action="yourfile.php"` to the file that holds the if login code. – Kip May 01 '22 at 09:28
  • @kip and vee thank you. I guess I solved the problem, today it works. I don't know why. However, as you suggested, I changed the action to login.php: copying and pasting I guess I forgot to change it from signup.php to login.php. Thank you for your time! – GiuRos May 01 '22 at 10:25

0 Answers0