我似乎无法使其正常工作,据我所知,这是对的?我可能做错了但我不确定,任何帮助都会非常感激
当我点击提交按钮时,没有任何反应......
<div id="form" action="#" method="post"> <!-- form -->
<p class="form-title">Enquire Today!</p>
<p class="form-description">Lorem ipsum dolor sit amet, consectetur adipiscing elit. In quis congue lorem, quis posuere ex. Suspendisse interdum semper urna mollis eleifend. Donec vulputate imperdiet nisi sed eleifend. Mauris vulputate quam libero, vel efficitur odio suscipit vel. Etiam efficitur lacinia dictum.<br><br>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In quis congue lorem, quis posuere ex. Suspendisse interdum semper urna mollis eleifend. Donec vulputate imperdiet nisi sed eleifend. Mauris vulputate quam libero, vel efficitur odio suscipit vel. Etiam efficitur lacinia dictum.</p>
<form class="form-left">
<p class="form-text">Name: <input type="text" name="name"></p>
<p class="form-text">Email: <input type="text" name="email"></p>
</form>
<form class="form-right">
<p class="form-text">Phone: <input type="text" name="phone"></p>
<p class="form-text">Company: <span class="form-margin"><input type="text" name="company"></span></p>
</form>
<a class="button-enquire" type="submit" name="submit" value="Submit" href="#form">Enquire Now!</a>
</div> <!-- form -->
<?php
if(isset($_POST['Submit'])){
$to = "placeholder";
$from = $_POST['email'];
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$company = $_POST['company'];
$subject = " - Form submission - " . $email;
$message = "Name: " . $name . "\n\n" . "Email: " . $email . "\n\n" . "Phone: " . $phone . "\n\n" . "Company: " . $company . "\n\n" . "Submitted form on the website, follow up with a call/email";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
}
?>
由于
答案 0 :(得分:1)
表单元素是出于原因。这不只是你可以放任何东西。
<a class="button-enquire" type="submit" name="submit"
value="Submit" href="#form">Enquire Now!</a>
以上代码不表单元素。请将其替换为:
<button>
<input type="submit">
它应该有效。此外,永远不要检查isset($_POST["submit"])
,因为它不可靠。
最后你的代码应该是:
<input class="button-enquire" type="submit" name="submit" value="Submit" />
另外,请确保将action
属性替换为您POST
这些内容的位置:
<form id="form" action="phpfilename.php" method="post">
最重要的是,请只有一个<form>
元素。看起来您有多个嵌套的<form>
元素,这些元素是无效的HTML 。最重要的是,您已将method
和action
提供给<div>
,它甚至不关心这些属性。
答案 1 :(得分:1)
检查一下,它将为您提供表格如何工作的基本知识,您将从以下代码中获得基本的想法,并需要更多地研究表单的工作原理 用你的路径phpfilename.php替换它将获得php post值。 你有写的方法和行动来div它将无法正常工作
<form id="form" action="phpfilename.php" method="post"> <!-- form -->
<p class="form-title">Enquire Today!</p>
<p class="form-description">Lorem ipsum dolor sit amet, consectetur adipiscing elit. In quis congue lorem, quis posuere ex. Suspendisse interdum semper urna mollis eleifend. Donec vulputate imperdiet nisi sed eleifend. Mauris vulputate quam libero, vel efficitur odio suscipit vel. Etiam efficitur lacinia dictum.<br><br>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In quis congue lorem, quis posuere ex. Suspendisse interdum semper urna mollis eleifend. Donec vulputate imperdiet nisi sed eleifend. Mauris vulputate quam libero, vel efficitur odio suscipit vel. Etiam efficitur lacinia dictum.</p>
<p class="form-text">Name: <input type="text" name="name"></p>
<p class="form-text">Email: <input type="text" name="email"></p>
<p class="form-text">Phone: <input type="text" name="phone"></p>
<p class="form-text">Company: <span class="form-margin">
<input type="text" name="company"></span></p>
<button class="button-enquire" type="submit" name="submit" value="Submit" >Enquire Now!</button>
</form>
<?php
if(isset($_POST['Submit'])){
$to = "placeholder"; // this is your Email address
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$company = $_POST['company'];
$subject = " - Form submission - " . $email;
$message = "Name: " . $name . "\n\n" . "Email: " . $email . "\n\n" . "Phone: " . $phone . "\n\n" . "Company: " . $company . "\n\n" . "Submitted form on the website, follow up with a call/email";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
}
?>
答案 2 :(得分:0)
如果您想使用form
post
发送method
,则需要设置method
,如下所示:
<form action="target.php" method="post">
<!-- form elements -->
</form>
如果您想确保向php后端发送内容,那么您需要在name
内输入value
和form
,如下所示:
<input type="submit" name="Submit" value="foobar">
name
将是密钥,value
将是服务器端的值。