首页 > 解决方案 > 如何让我的简单 php 表单转到我的 html 页面?

问题描述

我创建了一个简单的 PHP 代码,我希望它重定向到我的 HTML 页面,但我不知道该怎么做?有什么帮助吗?(顺便说一句,我不使用 MySQL)

I have attached the code below
https://jsfiddle.net/7ta2jyqv/

我只是希望它重定向到我创建的另一个页面,但我查看了教程,但没有一个有效

有人有我可以使用的简单代码吗?

标签: phphtmlforms

解决方案


您好,您可以使用它:

<!DOCTYPE html>
<html>
<head>
<title>Redirect Form To a Particular Page On Submit - Demo Preview</title>
<meta content="noindex, nofollow" name="robots">
<link href='css/redirect_form.css' rel='stylesheet' type='text/css'> <!--== Include CSS File Here ==-->
</head>
<body>
<div class="main">
<div class="first">
<h2>Redirect Form To a Particular Page On Submit using PHP</h2>
<form action="redirect_form.php" id="#form" method="post" name="#form">
<label>Name :</label>
<input id="name" name="name" placeholder='Your Name' type='text'>
<label>Email :</label>
<input id="email" name="email" placeholder='Valid Email Address' type='text'>
<label>Contact :</label>
<input id="contact" name="contact" placeholder='Contact' type='text'>
<label>Address:</label>
<input id="address" name="address" placeholder='Address' type='text' value="">
<input id='btn' name="submit" type='submit' value='Submit'>
<!---- Including PHP File Here ---->
<?php
include "include/redirect.php";
?>
</form>
</div>
</div>
</body>
</html>

并在用于提交表单的 php 中使用它:

<?php
if(isset($_POST['submit'])){
// Fetching variables of the form which travels in URL
$name = $_POST['name'];
$email = $_POST['email'];
$contact = $_POST['contact'];
$address = $_POST['address'];
if($name !=''&& $email !=''&& $contact !=''&& $address !='')
{
//  To redirect form on a particular page
header("Location:https://www.formget.com/app/");
}
else{
?><span><?php echo "Please fill all fields.....!!!!!!!!!!!!";?></span> <?php
}
}
?>

请记住,这只是一个示例。header 函数有助于在 php 中重定向。检查此链接:https ://www.formget.com/how-to-redirect-a-url-php-form/


推荐阅读