提交时更改输入类型


Changing input type on submit

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

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

使用这个:-

if ( $key == $unlock ) {
echo "<input type='text' name="test" value='".$_POST['test']."' ">";

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

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

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

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

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