好的,所以我对网页设计还很陌生。如何获取当前主题的联系表格?这是当前的HTML。
我需要知道如何编写PHP文件的代码;这是对的吗?
<div class="form row-fluid clearfix">
<div class="field span5">
<label>Your name:</label>
<input type="text" value="" class="req" placeholder="Placeholder text..." />
</div>
<div class="field span5">
<label>Your email:</label>
<input type="email" value="" class="req" />
</div>
<div class="clearfix"> </div>
<div class="field full">
<label>Your comment:</label>
<textarea class="span12" cols="2" rows="7"></textarea>
</div>
<button class="extruded"><span>Submit</span></button>
</div>
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: iclear';
$to = 'sales@tangledindesign.com';
$subject = 'Hello';
?>
如何链接该联系表单的PHP文件?
答案 0 :(得分:4)
第1步
使用表单HTML元素包装您的字段,该元素的action属性设置为php处理页面
第2步
根据php文件期望的内容命名表单字段
第3步
添加一些验证
第4步
提交并测试
示例强>
<强> HTML 强>
<form action="process.php" method="post">
First Name: <input type="text" name="first_name">
<input type="submit">
</form>
<强> PHP 强>
<?php
$first_name=$_POST["first_name"];
if($first_name=="John")
{
echo "Hi John!";
}
else
{
echo "Sorry Buddy, Don't really know you";
}
?>
注意强>
我没有为您提供完整解决方案的原因是您提到您是该编程中的新手,并且解决您的问题而不指导您如何操作是不公平的
答案 1 :(得分:0)
您需要使用标记包装HTML,并且不要忘记包含提交按钮:
<form action="process.php" method="post">
<div class="form row-fluid clearfix">
<input type="text" name="name">
<input type="text" name="email">
<input type="text" name="message">
<input type="submit" name="submit">
</div>
</form>
然后这是php(process.php)文件,用于从HTML表单中获取所有值:
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: iclear';
$to = 'sales@tangledindesign.com';
$subject = 'Hello';
希望得到这个帮助。
答案 2 :(得分:-1)
试试此代码
<?php
$toaddress ="youremail@domain.com" //change to your email address
$error ="";
if($_SERVER['REQUEST_METHOD']=="POST") {
$name=$_POST['name'] ;
$email=$_POST['email'] ;
$comment=$_POST['comment'] ;
if(!isset($name) || $name==""){
$error .="Please Enter your name <br/>";
}elseif (!isset($email) || $email==""){
$error .="Please Enter your email Address.<br/>";
}elseif(!isset($comment) || $comment==""){
$error .="Please Enter your Comments.<br/>";
}
if ($error ==""){
mail($toaddress,"Contact form",$comment)
}
}
?>
<?php echo $error ;?>
<form method='post' action='' enctype='multipart/form-data' id='news_form' name='post_form' >
<div class="form row-fluid clearfix">
<div class="field span5">
<label>Your name:</label>
<input name="name" type="text" value="" class="req" placeholder="Placeholder text..." />
</div>
<div class="field span5">
<label>Your email:</label>
<input type="email" value="" class="req" name="email" />
</div>
<div class="clearfix"> </div>
<div class="field full">
<label>Your comment:</label>
<textarea class="span12" cols="2" rows="7" name="comment"></textarea>
</div>
<input type="submit" value="submit" />
</div>
</form>