错误消息显示-Wordpress中的表单数据PHP条目

时间:2018-11-05 20:10:42

标签: javascript php jquery html wordpress

当前,我们有一个PHP表单,该表单使用一个条目重定向到主网站内的“私有”网站,我们使用以下代码:

<?php
//Turn the content from text box into variable
$page=$_POST['text'];

if($_POST['text']=='sit') {
//set up a redirect to that page
echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://example.com/index.php/private/sit\">";

}

else if($_POST['text']=='pony') {
//set up a redirect to that page
echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://example.com/wp-content/uploads/sites/2/client/pony/index.html\">";

}

最初,我们实施了最后一行,如果有人输入错误,它将刷新页面:

else {
   echo "<meta http-equiv=\"refresh\"content=\"0;URL=http://example.com\">";

}
?>

如何在表格旁边以粗体和红色显示提示“错误”的消息?

1 个答案:

答案 0 :(得分:0)

您可以在用于刷新的URL中发送参数。然后用Javascript刷新URL后检查该参数并添加错误。

在这种情况下,您将回显类似的内容

echo "<meta http-equiv=\"refresh\"content=\"0;URL=http://example.com?error=1\">";

然后在您的html中,使用Javascript或PHP检查URL参数并使用样式呈现错误。