在输入中创建激活码

时间:2014-10-04 09:19:53

标签: php html input activation

如何创建一个文本字段,用户只有在输入我创建的特定号码后才会被重定向到特定页面?如果代码无效,他会在该标签周围出现红色边框和某种消息(“不成功”或类似的东西)?

可以用php完成吗?

代码:

<!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>

2 个答案:

答案 0 :(得分:0)

您还需要在表单中添加此行

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

试试这个

<!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>";    
    }

}

答案 1 :(得分:0)

添加到按钮操作onClick(&#34; someaction.php&#34;)。比你刚用PHP中的$ _post读取数据并做你想做的事情