-1

好的,所以我对网页设计相当陌生。如何让我当前主题的联系表正常工作?这是当前的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">&nbsp;</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 文件?

4

3 回答 3

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";
}
?>

笔记

我没有为您提供完整解决方案的原因是您提到您是该编程的新手,仅解决您的问题而不指导您如何做是不公平的

于 2012-12-19T06:22:19.157 回答
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>

然后是从 HTML 表单中获取所有值的 php (process.php) 文件:

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];

$from = 'From: iclear'; 
$to = 'sales@tangledindesign.com'; 
$subject = 'Hello';

希望这有帮助。

于 2012-12-19T06:32:38.917 回答
-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">&nbsp;</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>
于 2012-12-19T06:37:06.317 回答