我有以下内容: 在提交时需要从密码切换到文本的第一个输入。
<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";
}
}
?>
答案 0 :(得分:0)
使用此: -
if ( $key == $unlock ) {
echo "<input type='text' name="test" value='".$_POST['test']."' ">";
} else {
echo "<input type='text' name="test" value='hidden123'>";
}
答案 1 :(得分:0)
要在提交时将Input元素的类型更改为Text,您可以使用将在Submit上执行的JQuery。
在If
条件中添加此代码以及成功消息。
echo "<script>$(document).ready(function(){
$('input[name=\"test\"').attr('type','text');
});</script>";
attr()
用于检索或设置元素的属性
PS:别忘了包含JQuery Library。