【问题标题】:Changing input type on submit提交时更改输入类型
【发布时间】:2015-03-10 12:12:09
【问题描述】:

我有以下几点: 提交时需要从密码切换为文本的第一个输入。

<input type="password" name="test" value="hidden123">

第二个输入是改变输入字段的关键。

<input type="text" name="key">

提交:

<input type="submit" name="grant" value="unlock">

最后是 PHP 代码:

<?php
if(isset($_POST['grant'])){
$pass=$_POST['test'];
$key=$_POST['key'];
$unlock = "123";
if ( $key == $unlock ) {
//change this so the input field 'test' changes to text rather than password
echo "success";
} else {
echo "fail";
}
}
?>

【问题讨论】:

  • 请更具体。您想在表单和输入类型更改的情况下显示 HTML?在echo "success";之前你想做什么?
  • 毫无意义。为什么需要在提交时更改类型?你是什​​么意思“改变领域的关键”?
  • 你在用ajax吗?否则您永远无法在提交时更改某些内容,您只能更改下一页,由 Harpartap 描述

标签: php html forms input


【解决方案1】:

使用这个:-

if ( $key == $unlock ) {

echo "<input type='text' name="test" value='".$_POST['test']."' ">";


}  else {

echo "<input type='text' name="test" value='hidden123'>";

}

【讨论】:

    【解决方案2】:

    要在提交时将输入元素的类型更改为文本,您可以使用将在提交时执行的 JQuery。

    将此代码与您的 成功 消息一起添加到 If 条件中。

    echo "<script>$(document).ready(function(){
               $('input[name=\"test\"').attr('type','text');
        });</script>";
    

    attr() 用于检索或设置元素的属性。
    PS:不要忘记包含 JQuery 库。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多