我搜索了基本的解释和示例,该示例和示例说明了如何使用同一基本php隐藏我的html表单“ onsubmit”,同时保持在同一页面上。我还需要通过电子邮件发送表格结果。我在这里和那里通常在初学者能力之外发现了一些困难。因此,我将分享一个基本示例,说明我认为这是最简单的方法。
带有php的HTML表单:
<?php
session_start();
//if you require login start session first thing at top
?>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
</script>
</head>
<title>Example Form </title>
<?php
//my database connection is in insert.php
include_once 'insert.php';
//Set up email to receive the desired form results
$submit = $_POST['submit'];
$to = "[email protected]";
$email = "[email protected]";
$user = $_SESSION['yoursession']; #this is if require user login
$companyname = $_POST['companyname'];
$companyurl = $_POST['companyurl'];
$ipaddress = $_SERVER['REMOTE_ADDR']; #capture user's ip address
$subject = $companyname;
if(isset($submit) && !empty($companyname || $companyurl)){
$headers = 'From:'. $email . "\r\n"; // Sender's Email
//$headers .= 'Cc:'. $email . "\r\n"; // Carbon copy to Sender
$body = "
Company Name: $companyname \n\n Company URL: $companyurl \n\n User IP Address: $ipaddressadvertise
";
if(mail($to, $subject, $body, $headers)){
//What will show after submit button selected...
echo "Successfully submitted!" . "<br />";
echo "<br />" . "<strong>Company Name: </strong> " . " " . "$companyname" . "<br />" . "<strong>Company Website: </strong> " . " " . "$companyurl" . "<br />";
}else {
echo "Oops something went wrong. Try again or come back later. " . "<br />";
}
}
?>
<body>
<?php
//This is where you start to wrap what you want to hide onsubmit.
$submit = $_POST['submit'];
if(!isset($submit)){
//Do NOT put closing curly brace leave open and see below.
?>
<form id="form" name="form" action="" method="post" <?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>
<table border="0">
<tr>Company Name: <align = "center"><input type = "text" id = "companyname" name = "companyname" value = "" placeholder = "Required" required><br /><br />
<tr>Company Website: <align = "center"><input type = "text" id = "companyurl" name = "companyurl" value = "" placeholder = "Required" required><br /><br />
<input type="submit" name="submit" id="submit" onclick = "location.href='mailto:[email protected]';" value="Submit!">
<tr></tr><br /><br />
<tr></tr>
<tr></tr>
</form>
<?php
} //This is where you put your closing curly brace wrapping all of the information you want to hide when submit button is clicked.
?>
</body>
</html>
单击提交按钮后,表单将消失,当通过电子邮件将结果发送给您时,消息将显示在同一页面上(而不重定向到另一页面)。>
注意:我在摘要中尝试了此操作,但没有成功。但是我将其加载到一个实时站点,并且可以完美运行而没有错误。
我搜索了基本的解释和示例,该示例和示例说明了如何使用同一基本php隐藏我的html表单“ onsubmit”,同时保持在同一页面上。我还需要通过电子邮件发送表格结果。我在这里找到了一些位,然后...
基本结构可以是这样的: