如何显示来自表单的 php 操作脚本的消息?
该表单是具有这些字段的用户登录。
<div id="register_user_box" class="inline_form" style="position: absolute; top: 20px; right: 10px; <br/>
<span id="user_msg"></span><br/>
<form action="register_user.php" method="post">
<input type="hidden" name="id" id="id" value="add" />
<input type="hidden" name="edit_user" id="edit_user" value="y" />
<table cellspacing="0px"> <tr><td>Username:</td></tr><tr><td>
<input type="text" name="uname" size="30" value="" class="inline_input"/></td> </tr> <tr><td>Email:</td></tr><tr><td>
<input type="text" name="uemail" size="30" value="" class="inline_input"/></td> </tr> <tr><td>Password:</td></tr><tr><td>
<input type="password" name="upass" size="30" class="inline_input"/></td> </tr> <tr><td>Confirm Password:</td></tr><tr> <td>
<input type="password" name="cpass" size="30" class="inline_input"/></td></tr> </table></td></tr> </table> <p>
<input class="button" type="submit" name="register" value="Register" style="float:right;"/></p>
</form>
</div>
php 脚本 register_user.php 检查密码是否匹配,如果不匹配则显示错误消息。该脚本会检查所有其他字段并在必要时打印一条消息。
<?php
$messages = array( 'usr_cred_req' => 'Must specify username, email, password.',
'usr_name_bad' => 'Bad username selection. Select a different usrename.',
'usr_name_exists' => 'Username selected already exists. Select a different username.',
'usr_email_bad' => 'Bad email selection. Select a different email.',
'usr_email_exists' => 'Email selected already exists. Select a different email.',
'usr_pass_notmached' => 'Passwords do not match. Type passwords again.',
'usr_not_added' => 'User not added.',
'usr_not_updated' => 'User not updated.',
'usr_added' => 'User added.'
);
$username = trim($_REQUEST['uname']);
$email = trim($_REQUEST['uemail']);
$password = md5(trim($_REQUEST['upass']));
$copasswd = md5(trim($_REQUEST['cpass']));
if ( $password != $copasswd ) { echo '<script> $("#usr_msg").html("'.$messages['usr_pass_notmached'].'"); </script>'; return;}
?>
错误消息未显示,浏览器离开页面。我希望浏览器留在页面上并将错误消息添加到跨度 user_msg。