如何在不依赖"pattern"的情况下使用属性"title"?
How to use the attribute "title" without relying on "pattern"?
所以我是 HTML/PHP 编程的初学者。我需要创建一个捕获错误的基本表单 (username/password/email),并且我发现 HTML 属性“title”在不符合模式时可以很好地显示它们。
但是,我不认为我可以创建一个在确认密码时捕获错误的模式(我的想法是强制用户输入相同的密码两次)。
我的目标是在捕获错误时显示类似这样的内容,即使没有模式被侵犯
这是我的代码,以备不时之需:
<input type="password" name="pw" size="16" value="<?=$infosVal[3]?>" placeholder="Password" minlength="6">
<input type="password" name="repeat" size="16" value="<?=$infosVal[4]?>" placeholder="Repeat" minlength="6">
有什么办法可以做到吗?谢谢
<form method='post'>
<input type="password" placeholder="Password" name='pass1' oninput="document.querySelector('#pass2').pattern=this.value" required=""> <br>
<input type="password" placeholder="Confirm Password" id='pass2' name='pass2'
pattern="" title="The second password does not match the first!" required="" /><br>
<input type="submit" name="check">
</form>
<?php
if(isset($_POST["check"])){
$password = $_POST["pass1"];
$confirmedPassword = $_POST["pass2"];
if($password === $confirmedPassword)
print('login success!');
}
?>
所以我是 HTML/PHP 编程的初学者。我需要创建一个捕获错误的基本表单 (username/password/email),并且我发现 HTML 属性“title”在不符合模式时可以很好地显示它们。
但是,我不认为我可以创建一个在确认密码时捕获错误的模式(我的想法是强制用户输入相同的密码两次)。
我的目标是在捕获错误时显示类似这样的内容,即使没有模式被侵犯
这是我的代码,以备不时之需:
<input type="password" name="pw" size="16" value="<?=$infosVal[3]?>" placeholder="Password" minlength="6">
<input type="password" name="repeat" size="16" value="<?=$infosVal[4]?>" placeholder="Repeat" minlength="6">
有什么办法可以做到吗?谢谢
<form method='post'>
<input type="password" placeholder="Password" name='pass1' oninput="document.querySelector('#pass2').pattern=this.value" required=""> <br>
<input type="password" placeholder="Confirm Password" id='pass2' name='pass2'
pattern="" title="The second password does not match the first!" required="" /><br>
<input type="submit" name="check">
</form>
<?php
if(isset($_POST["check"])){
$password = $_POST["pass1"];
$confirmedPassword = $_POST["pass2"];
if($password === $confirmedPassword)
print('login success!');
}
?>