我在一个 HTML 页面中有 2 个表单。一个表单发布到数据库,另一个表单发送一封电子邮件,其中包含表单中的详细信息。当我想到它时,这很简单,但尝试了很长时间没有成功。
HTML:
<ul class="slides">
<li>
<div id="contactFormContainer" class="container">
<div class="left">
<h1 class="uppercase">do you have project inquiry??</h1>
<form id="contactForm" method="POST" name="contactForm" action="">
<fieldset>
<p>
<label for="fullname">Fullname</label>
<input name="fullname" id="fullname" type="text">
</p>
<p>
<label for="email">Email</label>
<input name="email" id="contact_email" type="text">
</p>
<p>
<label for="fullname">Subject</label>
<input name="fullname" id="fullname" type="text">
</p>
<p>
<label for="fullname">Project Description</label>
<textarea name="message" id="message" rows="2" cols="20"></textarea>
</p>
<p>
<input class="btn" id="contactSubmit" type="submit" value="Submit">
</p>
</fieldset>
</form>
</div> <!-- end left -->
<div class="right">
<span class="head">Twitter Feeds</span>
<div class="twitter">
<!-- twitter feed will be generated -->
</div>
</div> <!-- end right -->
</div> <!-- end contact form container -->
</li>
<li>
<div class="head container">
<h2>coming soon...</h2>
</div>
<div class="body container">
<h1 class="uppercase">Subash.com is coming with new face.</h1>
Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Donec id elit non mi porta gravida at eget metus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Cum sociis natoque penatibus et magnis dis parturient.
</div>
<div class="footer container">
<p class="signup"><span class="cursive">sign up</span> ..be the first to be notified</p>
<div class="inputbox">
<form accept-charset="UTF-8" action="" name="subscribeForm" id="subscribeForm" method="post">
<input class="email_field" id="email" name="email" placeholder="Type your email address..." type="email">
<input class="submit_button" type="submit">
</form>
<div class="status">
<?php
if(isset($status)){
echo '<p>' . $status . '</p>';
} else {
echo '<p class="spam">We will never spam you.</p>';
}
?>
</div>
</div>
</div>
</li>
</ul>
PHP
<?php
require_once('includes/db.php');
require_once('includes/functions.php');
require_once('includes/validate.php');
if($_SERVER['REQUEST_METHOD'] == 'POST'){
// subscribe form
$email = trim($_POST['email']);
if(empty($email) || !valid_email($email)){
$status = 'Please provide valid email address.';
} else {
if(email_exist($email)){
$status = 'You are already subscribed.';
} else {
add_email($email);
$status = 'Thank you for subscribing.';
}
}
}
require 'index.tmpl.php';
?>
这段代码完全符合预期。但现在我需要提交另一个表格。我尝试在 REQUEST_METHOD 检查以下添加此代码但没有成功:
$fullname = $_POST['fullname'];
if(!empty($fullname)){
$status = 'sucess';
echo $status;
} else {
echo $fullname;
}
我也尝试过:
if (!empty($_POST['contactForm'])) {
//do something here;
}
if (!empty($_POST['subscribeForm'])) {
//do something here;
}
有什么我想念的吗?