如何从php禁用HTML按钮

时间:2015-05-28 00:03:47

标签: php jquery html

我正在尝试禁用提交按钮,当我从数据库中获取一些告诉我应该禁用它的触发器时,我在PHP的echo行中添加了一些代码但它没有用,我做错了什么?

PHP代码

$tries= CCL::Triescount($userip)->NumofTries;
                if ($tries > 2 ) //Check wheter they have tried more than 2 times then block them
                {
                    $msg = "More than 2 attempts, block user";
                    echo '<input type="submit" disabled="disabled" />';
                }
                else
                {
                     $tries++;
                     $msg = "Less than 2 attempts";
                     CCL::Updatetries($userip,$tries,0);
                     //insert into the DB

                }

HTML表格

<div class="ui-body ui-body-c ui-corner-all">
    <h1>Forgot Password</h1>
    <form>

        <label for="emailpassdlbl"> Please enter the e-mail associated with your account, and a new auto-generated password will be sent to this e-mail account.</label>
        <input type="text" id="email"><BR>

        <div class="right">
            <input type="submit" data-inline="true" value="Submit" disabled="disabled">
        </div>
    </form>
    <br/>
    <div data-role="popup" class="ui-body ui-body-c ui-corner-all">
        <h2 id="result"></h2>
        <a href="#" data-role="button" onclick="$(this).closest(\'[data-role=popup]\').popup(\'close\');" class="right">OK</a>
    </div>

1 个答案:

答案 0 :(得分:0)

如果您使用PHP更改整个代码以禁用它,为什么不完全删除提交功能?

例如:

 if ($tries > 2 ) //Check wheter they have tried more than 2 times then block them
                {
                    $msg = "More than 2 attempts, block user";
                    echo '<button type="button" disabled" />';
                }

正如您所看到的,我们实际上删除了type="submit"并将其替换为type="button"它应该看起来仍然是相同的按钮,但它不会提交表单(除了禁用的属性)。< / p>