skip to Main Content

I have this form for resetting passwords:

<form action = "resetpwd.inc.php" method = "post" class = "form">
    <div class = "input-group">
        <input type = "text" name = "email" placeholder = "Enter your email:">
        <span class = "icon">✉</span>
    </div>
    <div class = "input-group">
        <button class = "submitbtn" type = "submit">Reset Password</button>
    </div>
</form>

I also have a resetpwd.inc.php file with the following code that handles the form submission:

if(isset($_POST["submitbtn"]))

My goal is to have this PHP code execute when I submit the form, however it isn’t doing that and it’s just refreshing the page.

2

Answers


  1. You are trying to check if the key submitbtn exists within the $_POST array, which only contains your form inputs, however submitbtn is a CSS class on the <button> element rather than a name attribute.

    To determine if a request made to the page is a POST request, you can check to see if the array is not empty:

    if (!empty($_POST) {
        $username = filter_input(INPUT_POST, "username");
    
        // Do something with $username
    }
    

    You can then use filter_input to retrieve the form value from the username text input field, the identifier "username" comes from the name="username" you set in the <input> element.

    Your form action will then redirect you to the resetpwd.inc.php page and send a POST request.

    Login or Signup to reply.
  2. I think that you could be missing name=” property on your button, right here you have:

    <button class = "submitbtn" type = "submit">Reset Password</button>
    

    Instead, try this:

    <button class = "submitbtn" name="submitbtn" type ="submit">Reset Password</button>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search