我已经在WordPress插件中创建了一个表单,使用的是普通的HTML标签。我刚刚用echo测试了文本框提交的值,它工作得很好。提交表单后,我需要重定向或在同一页面中显示成功/失败消息。提交表单后如何显示成功或失败消息?
发布于 2018-06-12 23:20:01
对我起作用的是以下内容:
// After form save function ends do:
wp_redirect($your_post_url . '&saved=1');
exit;
// Wherever you need the html do:
if (isset($_GET['saved'])) echo
'<div class="updated">
<p>' . __('Success! Values have been saved.') . '</p>
</div>';发布于 2015-12-09 15:26:27
<form method="post" role="form">
<div class="form-group">
<label for="txt">Enter Text</label>
<input type="text" class="form-control" id="txt1" name="txt1" value="" placeholder="Enter your text..." />
</div>
<button type="submit" name="send" class="btn btn-default">Send</button>
</form>
<?php
if(isset($_POST['send'])) {
$txt1 = trim($_POST['txt1']);
$count=0;
if(empty($txt1)) {
echo '<div class="error">Please enter your text.</div>';
} else {
header("Location: http://www.yourwebsite.com/user.php");
$count=1;
if($count=1)
{
echo '<label for="msg">Succes Message</label>';
}
}
}
?>https://stackoverflow.com/questions/34172235
复制相似问题