我正在使用“ ReusableForms”中的表单,并且工作正常,但是由于Bootstrap版本冲突,我无法在Bootstrap 4.2.1网页中包含该表单,我只能将表单作为“在它上面自己的”页面,这很好,但是在提交表单并显示成功消息之后,我希望表单重定向到我网站的首页。这是处理程序和html表单的代码:
<form method="post" id="reused_form" >
<button class="button-primary" type="submit">Submit</button>
</form>
<div id="success_message" style="display:none">
<h3>Submitted the form successfully!</h3>
<p> Eric will get back to you soon. </p>
</div>
<div id="error_message" style="width:100%; height:100%; display:none; "> <h3>Error</h3> Sorry there was an error sending your form. </div>
php代码:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
/*
Tested working with PHP5.4 and above (including PHP 7 )
*/
require_once './vendor/autoload.php';
use FormGuide\Handlx\FormHandler;
$pp = new FormHandler();
$validator = $pp->getValidator();
$validator->fields(['Name','Email'])->areRequired()->maxLength(50);
$validator->field('Email')->isEmail();
$validator->field('Message')->maxLength(6000);
$pp->requireReCaptcha();
$pp->getReCaptcha()->initSecretKey('');
$mailer = $pp->getMailer();
//Using SMTP account
$mailer->IsSMTP();
$mailer->SMTPAuth = true;
$mailer->SMTPSecure = "tls";
$mailer->Host = "";
$mailer->Username = "";
$mailer->Password = "";
$mailer->setFrom('', 'Camp Bay Form');
$pp->sendEmailTo(''); // ← Your email here
echo $pp->process($_POST);
我一直在互联网上搜索处理程序中的其他代码,并且尝试了隐藏的重定向输入,但没有任何效果,我认为处理程序代码的编写方式与那里的其他代码不匹配。 / p>
我希望可以很容易地将其添加到处理程序代码中,我只需要知道在其中添加什么即可使重定向工作!
答案 0 :(得分:0)
请更具体地说明您的问题。据我所知,我看到您需要HTML表单中的目标。
在HTML中添加action =“ example.com/index.php”。
<form method="post" id="reused_form" action="/handler.php">
<button class="button-primary" type="submit">Submit</button>
</form>
<div id="success_message" style="display:none">
<h3>Submitted the form successfully!</h3>
<p> Eric will get back to you soon. </p>
</div>
<div id="error_message" style="width:100%; height:100%; display:none; "> <h3>Error</h3> Sorry there was an error sending your form. </div>
尽管我不建议这样做。最好将所有文件都放在同一文件中:
```
<?php
if(isset($_POST)) {
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
/*
Tested working with PHP5.4 and above (including PHP 7 )
*/
require_once './vendor/autoload.php';
use FormGuide\Handlx\FormHandler;
$pp = new FormHandler();
$validator = $pp->getValidator();
$validator->fields(['Name','Email'])->areRequired()->maxLength(50);
$validator->field('Email')->isEmail();
$validator->field('Message')->maxLength(6000);
$pp->requireReCaptcha();
$pp->getReCaptcha()->initSecretKey('');
$mailer = $pp->getMailer();
//Using SMTP account
$mailer->IsSMTP();
$mailer->SMTPAuth = true;
$mailer->SMTPSecure = "tls";
$mailer->Host = "";
$mailer->Username = "";
$mailer->Password = "";
$mailer->setFrom('', 'Camp Bay Form');
$pp->sendEmailTo(''); // ← Your email here
$output = $pp->process($_POST);
}
?>
<form method="post" id="reused_form" >
<button class="button-primary" type="submit">Submit</button>
</form>
<?php echo $output; ?>
```
答案 1 :(得分:0)
请参阅jQuery表单提交处理:http://reusableforms.com/d/a/contact-form-bootstrap
我认为您必须像这样在javascript中进行重定向:
<script>
$(function()
{
function after_form_submitted(data)
{
if(data.result == 'success')
{
$('form#reused_form').hide();
$('#success_message').show();
$('#error_message').hide();
setTimeout(function () {
window.location.href = "/"; // Your redirection here
}, 2000);
}
else
{
// Your code here, see documentation
}//else
}
</script>