用户(客户端)已请求AddressForm.php,其中包含html表单。从那里,用户向Confirmation.php发出http服务器请求,并根据发布的表单值,服务器应该发送新的屏幕(基于Confirmation.php),或者它应该部分更新旧屏幕(基于AddressForm) .php if Confirmation.php返回错误),替换html标签<DIV name="errormessage">no errors</DIV> into <DIV name="errormessage">error 123</DIV>
如何实现旧网站<DIV>
的部分更新,而无需再次重新计算旧网站的值?
答案 0 :(得分:0)
简而言之,作为示例,在Confirmation.php文件中,我使用会话执行以下操作;
<div class="form-group">
@Html.LabelFor(model => model.Organization.Website, htmlAttributes: new { @class =
"control-label col-md-3"})
<div class="col-md-5">
@Html.EditorFor(model => model.Organization.Website, new
{htmlAttributes = new { @class = "form-control", id = "txtWebsite" } })
@Html.ValidationMessageFor(model => model.Organization.Website, "", new { @class =
"text-danger" })
</div>
</div>
如果表单中有错误,在这种情况下为空消息,则以下情况属实;
session_start(); // use sessions
$err = array();
$email = $_POST['email'];
$message = $_POST['message'];
//you may have an empty first name, last name or email (or message)
if(empty($email)) {
$err[] = 'Please enter an email address';
}
if(empty($message)) {
$err[] = 'Please enter a message to send';
}
<小时/>
然后,在您的AddressForm.php文件中,无论您希望出现何种错误消息,您都可以简单地输入:
if(count($err)) {
$_SESSION['msg']['reg-err'] = implode('<br />',$err);
header("Location: AddressForm.php");
exit;
}
else {
$_SESSION['msg']['reg-success']= "Thank you for submitting your message";
header("Location: AddressForm.php");
exit;
}