我使用常规HTML标记在WordPress插件中创建了一个表单。我刚用echo测试了文本框提交的值,它运行正常。我需要在提交表单后在同一页面中重定向或显示成功/失败消息。如何在表单提交后显示成功或失败消息?
答案 0 :(得分:0)
<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>';
}
}
}
?>
答案 1 :(得分:0)
对我有用的是:
// 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>';