Search code examples
phphtmlinputactivation

Creating activation code in input


How can I create a textfield in which the user would be redirected to specific page, only after he has entered the specific number created by me? And if the code is invalid he would get a red border around that tab and some kind of message ("not successful" or something like this)?

Could that be done with php?

Code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Activation</title>
</head>
<body>
    <div class="activation">
        <label class="label">Please enter activation code to continue:</label><br>
        <input type="text" name="activation"/>
        <button type="submit" class="button">Activate</button>
    </div>
</body>
</html>

Solution

  • You need to add this line as well in your form

    <form action="" method="POST">
    

    try this

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Activation</title>
    </head>
    <body>
        <div class="activation">
            <form action="" method="POST">
            <label class="label">Please enter activation code to continue:</label><br>
            <input type="text" name="activation"/>
            <button type="submit" class="button">Activate</button>
        </div>
    </body>
    </html>
    
    <?php
    
    if(isset($_POST['activation'])){
        $activation=$_POST['activation'];
        //Lets the code is 4
        if($activation==4)
        {
            //Your file name(lets say you want to redirect to index.html)
            header('Location:index.html');
        }
     else {
            echo "<div id='divname'>And the the code of div goes here.</div>";    
        }
    
    }