如何使此联系​​表格生效?

时间:2016-05-15 06:42:38

标签: javascript php html css web

我无法对此进行编辑,请与我们联系。表单代码工作并将邮件传递到我的邮箱。

说我希望将消息发送到我的电子邮箱:doherty@noob.com,如何编辑此代码执行任务?



<div class="conatct-form">
			<ul class="form">
				<li>
				<input type="text" class="text" value="Name*" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Name*';}" >
				</li>
				<li>
				<input type="text" class="text" value="Email*" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Email*';}" >
				</li>
				<li>
				<textarea value="Message*:" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Your Message*';}">Message*</textarea>
				</li>
				<div class="sub-button">
					<input type="submit" value="SEND">
				</div>

			</ul>
		</div>
&#13;
&#13;
&#13;

5 个答案:

答案 0 :(得分:1)

我已优化您的代码并添加了一些PHP代码

PHP代码

 <?php
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];

    if (isset($name, $email, $message)) {
        // Insert into database
        $query = mysql_query("INSERT INTO contacts ...");

        if ($query) {
            // send email using phpmailer, sendmail, ...
            mail($mail, 'Subject', $message, '...');
        }
    }
?>

HTML

<form id="contact-form" method="post">
    <ul>
        <li>
            <!--
                Substituting the code below
                <input type="text"
                       value="Name *"
                       onfocus="this.value=''"
                       onblur="if (this.value == '') {this.value = 'Name *'}" />

                use the placeholder attribute instead
            -->
            <input type="text" name="name" placeholder="Name *" />
        </li>
        <li>
            <input type="text" name="email" placeholder="Email *" />
        </li>
        <li>
            <textarea name="message" placeholder="Message *"></textarea>
        </li>
        <li>
            <input type="submit" value="Send" />
        </li>
    </ul>
</form>

答案 1 :(得分:0)

您需要将HTML输入包装在元素中,以便使正确的表单起作用。

因此,您需要以下标记:

EngagementMetric.
    select("metrics_date as date").
    select("sum(likes) as likes_count").
    select("sum(comments) as comments_count").
    select("sum(shares) as shares_count").
    select("sum(views) as views_count").
    select("sum(clicks) as clicks_count").
    where(engagement_id: engagement_ids).        
    group("date").
    order("date desc").
    to_json

 # => [{ date: "2016-05-01", likes_count: 123, comments_count: 456, ... }, {...}]

有关string time = DateTime.Now.ToString("dd-MM-yyyy"); int burned = 0; string s = (comboBox1.SelectedItem).ToString(); cnn.Open(); string cmdText = @"SELECT calorificValue FROM myfitsecret.food WHERE name=@name; SELECT daily_gained FROM myfitsecret.calorie_tracker WHERE sportsman_id=@sportsman_id"; using (MySqlCommand cmd = new MySqlCommand(cmdText, cnn)) { // Add both parameters to the same command cmd.Parameters.Add("@name", MySqlDbType.String).Value = s; cmd.Parameters.Add("@sportsman_id", MySqlDbType.String).Value = Login.userID; using (MySqlDataReader reader = cmd.ExecuteReader()) { // get sum from the first result if (reader.Read()) burned += (Convert.ToInt32(reader[0])*int.Parse(textBox1.Text)); // if there is a second resultset, go there if (reader.NextResult()) if (reader.Read()) burned += Convert.ToInt32(reader[0]); } cmd.Connection.Close(); MySqlCommand cmd2 = new MySqlCommand("update myfitsecret.calorie_tracker set daily_gained=@daily_gained where sportsman_id=@sportsman_id and Date=@Date"); cmd2.CommandType = CommandType.Text; cmd2.Connection.Open(); cmd2.Parameters.AddWithValue("@daily_gained", burned); cmd2.Parameters.AddWithValue("@Date", time); cmd2.Parameters.Add("@sportsman_id", MySqlDbType.String).Value = Login.userID; cmd2.ExecuteNonQuery(); 标记的格式和参数的详细信息,请参阅Mozilla文档:

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form

答案 2 :(得分:0)

此处未提交提交,因为内容未包含在表单标记内。 所有内容都应该包含在标签中,该标签具有某些php / java文件的action属性,该文件验证用户传递的数据并提交给数据库。

请查看mdn上的表格标签以获取更多信息。

答案 3 :(得分:0)

而不是你使用     if(isset($ name,$ email,$ message)){...} 有HTML5&#39;必需&#39;在你的标签中会更好。例如      此外,您提交类型需要具有名称。该名称将用于处理您的表单。

答案 4 :(得分:0)

contact.php页面。下面的表单处理自己,因为该方法的名称是contact.php。

<form id="contact-form" method="post" action="contact.php" >
<input type="text" name="name" placeholder="Name" />
<input type="text" name="subject" placeholder="Subject *" />
<input type="text" name="email" placeholder="Email *" />
<textarea name="message" placeholder="Message *"></textarea>
<input type="submit" value="Send" name="send"/>
</form>

<?php
if (isset($_POST['send']))  {
$to = "youremail@something.com";
$subject = $_POST['subject'];
$message = $_POST['message'];
$from = $_POST['email'];
$headers = "From: $from $name";
$sent = mail($to,$subject,$message,$headers);

if ($sent)  {
echo "<p style = 'color: #00ff00;'>Message was sent.</p>";
}
else    {
echo "<p style = 'color: #ff0000;'>Message was not sent.</p>";
}
}
?>