我有一个给定文章的评论列表,我有一个表单下的评论为用户添加自己的评论。移动到页面刷新后的网页的一部分
我使用php来做一些表单验证。
这是该过程:
- 用户填写表格(或不)和点击提交按钮。页面刷新。
- PHP验证用户输入,并在无错误时提交注释,或者 生成错误列表。
如果存在错误,则显示错误。
问题是,我想要在表单之前显示错误,但是当epage刷新时,页面的顶部会显示出来,我需要它直接显示错误和表单(很多像一个页面锚点)
这可能吗?
这在点击提交按钮
if(empty($errors)){
$result = post_comment('event',$event_id, $sendername, $senderemail, $userurl, $comment);
if ($result == 'Correct') {
//header('Location: /'.$_SERVER['REQUEST_URI']);
header('Location: '.$_SERVER['REQUEST_URI']);
}
else {
$send_error = $result;
之后被调用,这是评论附近,形成我想要的页面去,如果存在
// If there was an error sending the email, display the error message
if (isset($send_error)) {
echo "<a name=\"commentsform\"></a>";
echo "There was an error: ".$send_error;
}
/**
* If there are errors and the number of errors is greater than zero,
* display a warning message to the user with a list of errors
*/
if (isset($errors) && count($errors) > 0) {
echo ("<h2 class='errorhead'>There has been an error:</h2><p><span class='bold'>You forgot to enter the following field(s)</span></p>");
echo ("<ul id='validation'>\n");
foreach ($errors as $error) {
echo ("<li>".$error."</li>\n");
}
echo ("</ul>\n");
}
}
}
使用跳转到本地浏览器的能力如果url的哈希值匹配,则为id:'example.com#id'将转到http://example.com并跳转到id为id的元素 –