【问题标题】:Making an HTML form Work使 HTML 表单工作
【发布时间】:2017-11-28 17:00:37
【问题描述】:

我正在尝试制作我的第一个联系表。我已经完成了 HTML & CSS 部分。可能 HTML 标记中有一些错误。

现在我的 HTML/CSS 看起来不错,我需要使其正常工作,以便将提交的内容发送到我的电子邮件,并且页面会显示感谢消息或重定向到感谢页面。

有人可以帮我编写为表单创建安全功能以使其工作的代码吗?

我还想在表单中添加验证码以避免垃圾邮件提交。

表单的实时链接-http://wishamemory.com/makeawish/index.html

表单的HTML代码是这样的:

<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">
  <title>Quick Minimal Contact Form</title>



      <link rel="stylesheet" href="css/style.css">


</head>

<body>
  <link href='https://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css'>

<form id="contact-form">
  <p>WISH A MEMORY!</p>
  <p>I
    <label for="your-wish">wish</label> for
    <input type="text" name="your-wish" id="wish" minlength="3" placeholder="(describe your wish here)" required></p>

  <p>  
    <label for="your-location">in</label>
    <input type="text" name="your-location" id="location" minlength="3" placeholder="(location in Goa only)" required>

    <label for="your-date">on</label>
    <input type="text" name="your-date" id="date" minlength="3" placeholder="(dates)" required></p>

  <p>***********</p>
  <p>
    <label for="your-credits">Is this wish for yourself or dedicated to someone else?</label>
    <input type="text" name="your-credits" id="credits" minlength="3" placeholder="Who is the lucky one?" required></p>
  <p>
    <label for="your-budget">Preferred budget to make this wish a reality:</label>
    <input type="text" name="your-budget" id="budget" minlength="3" placeholder="(amount in INR)" required></p>

  <p>
    <label for="your-maxbudget">Maximum you can spend to make the experience even more memorable:</label>
    <input type="text" name="your-maxbudget" id="maxbudget" minlength="3" placeholder="(let's make it special)" required></p>

  <p>
    <label for="your-reason">Why do you think this wish deserves becoming a memory?</label>
    <textarea name="your-reason" id="your-reason" placeholder="(Not all wishes come true. Share some background and the importance of this wish)" class="expanding" required></textarea>
    </p>

  <p>Personal details</p>
  <p>
    <label for="your-name">Name</label>
    <input type="text" name="your-name" id="name" minlength="3" placeholder="(full name)" required></p>
  <p>
    <label for="email">Email address</label>
    <input type="email" name="your-email" id="email" placeholder="(your email address)" required>
  </p>
  <p>
    <label for="phone">Mobile number</label>
    <input type="text" name="your-phone" id="phone" placeholder="(mobile number)" required>
  </p>

    <p>
    <button type="submit">
      <svg version="1.1" class="send-icn" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="100px" height="36px" viewBox="0 0 100 36" enable-background="new 0 0 100 36" xml:space="preserve">
        <path d="M100,0L100,0 M23.8,7.1L100,0L40.9,36l-4.7-7.5L22,34.8l-4-11L0,30.5L16.4,8.7l5.4,15L23,7L23.8,7.1z M16.8,20.4l-1.5-4.3
    l-5.1,6.7L16.8,20.4z M34.4,25.4l-8.1-13.1L25,29.6L34.4,25.4z M35.2,13.2l8.1,13.1L70,9.9L35.2,13.2z" />
      </svg>
      <small>send</small>
    </button>
  </p>
</form>

<small class='website'>Powered by <a href='http://wishamemory.com/' target='_blank'>wishamemory.com</a></small>
</body>
</html>

我尝试按如下方式制作mail.php进行测试。并在我的 HTML 文件中更改了

<form id="contact-form"> 

为此

<form action="mail.php" method="POST">

mail.php 文件

<?php 
$your-wish = $_POST['your-wish'];
$your-location = $_POST['your-location'];
$your-date = $_POST['your-date'];
$formcontent="From: $your-name \n Message: $wish";
$recipient = "arminbaig@gmail.com";
$subject = "Contact Form";
$mailheader = "From: $your-email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>

但我在此网址上收到以下错误 - http://wishamemory.com/makeawish/mail.php

此页面无法正常工作

wishamemory.com 目前无法处理此请求。 HTTP 错误 500

我哪里错了?

【问题讨论】:

  • 您的表单需要一个 PHP 部分,到目前为止您尝试过什么?
  • 很高兴看到您为自己解决此问题而尝试了什么,这将向我们表明您在发布问题之前已经对此进行了研究。当你尝试时,你也会学习。如果有人只是给你一个答案/解决方案,那一切都是徒劳的,我这样说是为了/你的未来。然后,您可以编辑您的帖子以包含可能失败的内容;即使这表明你的努力。请记住,我们总是很乐意提供帮助。
  • 你知道这里有很多类似的答案,还有谷歌搜索这个主题的教程?到目前为止你有没有尝试过?
  • 这些是一些简单但不那么简单(也非常笼统)的问题,您应该首先自己研究。如果您进行了研究但仍有特定问题/疑问,那么您可以在此处提问。
  • 联系表单是您在学习 PHP 时首先要做的基本练习之一。那里有字面意思,我的意思是字面意思,成千上万的例子。但是……你无视这些,直接来这里要求我们为你做这件事?

标签: php html


【解决方案1】:

&lt;form&gt; 标签中缺少 action 属性 像这样&lt;form id="something" action="link-to-php file"&gt;

你必须像这样在 action 属性中添加 mail.php,

    <form action="mail.php" id="contactform" method="post">
-------
------------
</form>

【讨论】:

  • 感谢您的回复.. 我尝试了您的建议.. 但收到此错误此页面无法正常工作 wishamemory.com 目前无法处理此请求。 HTTP 错误 500
  • 您的 php 服务器设置为电子邮件吗?
  • 您需要一个有效的 SMTP 服务器来处理该请求,我相信您可以使用 gmail 但您需要使用身份验证进行连接...您可能需要考虑使用 php 电子邮件库...我使用梨
  • 确保您已在 php ini 文件中启用错误检测
【解决方案2】:
<!DOCTYPE html>
<html>
<head>
<style>
* {
    box-sizing: border-box;
    margin:0px;
    padding:0px;
}

input[type=text], select, textarea{
    width: 100%;
    padding: 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
    resize: vertical;
}

label {
    padding: 12px 12px 12px 0;
    display: inline-block;
}

input[type=submit] {
    background-color: #4CAF50;
    color: white;
    padding: 12px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    float: right;
}

input[type=submit]:hover {
    background-color: #45a049;
}

.container {
    border-radius: 5px;
    background-color: #f1f1f1;
    padding: 20px;
}

.col-25 {
    float: left;
    width: 25%;
    margin-top: 6px;
}

.col-75 {
    float: left;
    width: 75%;
    margin-top: 6px;
}

/* Clear floats after the columns */
.row:after {
    content: "";
    display: table;
    clear: both;
}

/* Responsive layout - when the screen is less than 600px wide, make the two columns stack on top of each other instead of next to each other */
@media (max-width: 600px) {
    .col-25, .col-75, input[type=submit] {
        width: 100%;
        margin-top: 0;
    }
}
</style>
</head>
<body>

<h2>Responsive Form</h2>
<p>Resize the browser window to see the effect. When the screen is less than 600px wide, make the two columns stack on top of each other instead of next to each other.</p>

<div class="container">
  <form action="/action_page.php">
    <div class="row">
      <div class="col-25">
        <label for="fname">First Name</label>
      </div>
      <div class="col-75">
        <input type="text" id="fname" name="firstname" placeholder="Your name..">
      </div>
    </div>
    <div class="row">
      <div class="col-25">
        <label for="lname">Last Name</label>
      </div>
      <div class="col-75">
        <input type="text" id="lname" name="lastname" placeholder="Your last name..">
      </div>
    </div>
    <div class="row">
      <div class="col-25">
        <label for="country">Country</label>
      </div>
      <div class="col-75">
        <select id="country" name="country">
          <option value="australia">Australia</option>
          <option value="canada">Canada</option>
          <option value="usa">USA</option>
        </select>
      </div>
    </div>
    <div class="row">
      <div class="col-25">
        <label for="subject">Subject</label>
      </div>
      <div class="col-75">
        <textarea id="subject" name="subject" placeholder="Write something.." style="height:200px"></textarea>
      </div>
    </div>
    <div class="row">
      <input type="submit" value="Submit">
    </div>
  </form>
</div>

</body>
</html>

【讨论】:

  • 我不明白您回复的相关性。这是干什么用的?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-07
  • 1970-01-01
相关资源
最近更新 更多