Я использую форму из «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);
Я искал в Интернете, пытаясь использовать другой код в обработчике, и я пробовал скрытый ввод перенаправления, и ничего не работает, я предполагаю, что то, как написан код обработчика, не соответствует другим.
Я ожидаю, что это очень легко добавить в код обработчика, мне просто нужно знать, что туда добавить, чтобы перенаправление заработало!






Пожалуйста, конкретизируйте свой вопрос. Из того, что я могу сказать, я вижу, что вам нужен пункт назначения в HTML-форме.
Добавьте action="example.com/index.php" в свой HTML.
<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; ?>
```
См. Обработку отправки формы 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>