Php 在一页上验证两个表单
我试图将两个表单合并到一个页面中,但php将这两个表单视为一个表单,我很难理解如何将它们分开。提前感谢你的帮助。这是我的表格1的html:Php 在一页上验证两个表单,php,html,forms,validation,Php,Html,Forms,Validation,我试图将两个表单合并到一个页面中,但php将这两个表单视为一个表单,我很难理解如何将它们分开。提前感谢你的帮助。这是我的表格1的html: <div id="message"> <h3>Message Us</h3> <form action="?" method="POST" onsubmit="return saveScrollPositions(this);">
<div id="message">
<h3>Message Us</h3>
<form action="?" method="POST" onsubmit="return saveScrollPositions(this);">
<input type="hidden" name="scrollx" id="scrollx" value="0" />
<input type="hidden" name="scrolly" id="scrolly" value="0" />
<div id="msgbox1">
<label for="msgname">Name:</label>
<input type="text" id="msgname" name="msgname" placeholder=" Required" />
<label for="msgemail">Email:</label>
<input type="text" id="msgemail" name="msgemail" placeholder=" Required" />
<label for="msgphone">Phone:</label>
<input type="text" id="msgphone" name="msgphone" placeholder="" />
<label for= "msgtopic">Topic:</label>
<select id="msgtopic" name="msgtopic">
<option value="general">General</option>
<option value="stud">Property Price Enquiry</option>
<option value="sale">Bull Sale Enquiry</option>
</select>
</div><!--- msg box 1 -->
<div id="msgbox2">
<textarea id="emailmessage" name="emailmessage" rows="7" colums="25" placeholder="Your Message?"></textarea>
<input type="submit" value="Send message" />
<p id="feedback"><?php echo $feedback2; ?></p>
</div><!--- msg box 2 -->
</form><!--- end form -->
</div><!--- end message -->
<?php
$to = '418@hotmail.com.au';
$subject = 'Morrison Property Group website enquiry';
$msgname = $_POST ['msgname'];
$msgemail = $_POST ['msgemail'];
$msgphone = $_POST ['msgemail'];
$msgtopic = $_POST ['msgtopic'];
$message = $_POST ['emailmessage'];
$body = <<<EMAIL
This is a message from $msgname
Topic: $msgtopic
Message: $emailmessage
From $name
Phone: $msgphone
Email: $msgemail
EMAIL;
$header = ' From: $msgemail ';
if($_POST){
if($msgname == '' || $msgemail == '' || $emailmessage == ''){
$feedback = '*Please fill out all the fields';
}else {
mail($to, $subject, $body, $header);
$feedback2 = 'Thanks for the message. <br /> We will contact you soon!';
}
}
?>
给我们留言
姓名:
电邮:
电话:
主题:
一般的
物业价格查询
牛市询盘
表单1的php:
<div id="message">
<h3>Message Us</h3>
<form action="?" method="POST" onsubmit="return saveScrollPositions(this);">
<input type="hidden" name="scrollx" id="scrollx" value="0" />
<input type="hidden" name="scrolly" id="scrolly" value="0" />
<div id="msgbox1">
<label for="msgname">Name:</label>
<input type="text" id="msgname" name="msgname" placeholder=" Required" />
<label for="msgemail">Email:</label>
<input type="text" id="msgemail" name="msgemail" placeholder=" Required" />
<label for="msgphone">Phone:</label>
<input type="text" id="msgphone" name="msgphone" placeholder="" />
<label for= "msgtopic">Topic:</label>
<select id="msgtopic" name="msgtopic">
<option value="general">General</option>
<option value="stud">Property Price Enquiry</option>
<option value="sale">Bull Sale Enquiry</option>
</select>
</div><!--- msg box 1 -->
<div id="msgbox2">
<textarea id="emailmessage" name="emailmessage" rows="7" colums="25" placeholder="Your Message?"></textarea>
<input type="submit" value="Send message" />
<p id="feedback"><?php echo $feedback2; ?></p>
</div><!--- msg box 2 -->
</form><!--- end form -->
</div><!--- end message -->
<?php
$to = '418@hotmail.com.au';
$subject = 'Morrison Property Group website enquiry';
$msgname = $_POST ['msgname'];
$msgemail = $_POST ['msgemail'];
$msgphone = $_POST ['msgemail'];
$msgtopic = $_POST ['msgtopic'];
$message = $_POST ['emailmessage'];
$body = <<<EMAIL
This is a message from $msgname
Topic: $msgtopic
Message: $emailmessage
From $name
Phone: $msgphone
Email: $msgemail
EMAIL;
$header = ' From: $msgemail ';
if($_POST){
if($msgname == '' || $msgemail == '' || $emailmessage == ''){
$feedback = '*Please fill out all the fields';
}else {
mail($to, $subject, $body, $header);
$feedback2 = 'Thanks for the message. <br /> We will contact you soon!';
}
}
?>
表格2的html:
<div id="mail">
<h3>Sign Up to MPG mail...</h3>
<div id= "form">
<form action="?" method="POST" onsubmit="return saveScrollPositions(this);">
<input type="hidden" name="scrollx" id="scrollx" value="0" />
<input type="hidden" name="scrolly" id="scrolly" value="0" />
<fieldset>
<input type="text" id="name" name="name" placeholder="Name" />
<input type="text" id="email" name="email" placeholder="Email" />
<input type="submit" name="submit" value="Sign Up" />
</fieldset>
</form><!--End Form -->
<p id="feedback"><?php echo $feedback; ?></p>
</div><!-- End Form -->
</div><!-- End mail -->
<?php
$to = '@morrisonpg.com.au';
$subject = 'Sign Up';
$name = $_POST ['name'];
$email = $_POST ['email'];
$body = <<<EMAIL
Please add $name with the email $email to your mailing list.
EMAIL;
$header = ' From: $name ';
if($_POST){
if($name == '' || $email == ''){
$feedback = '*Please fill out all the fields';
}else {
mail($to, $subject, $body, $header);
$feedback = 'Thanks for signing up. <br /> You will receive correspondence soon!';
}
}
?>
注册MPG邮件。。。
以及表单2的php:
<div id="mail">
<h3>Sign Up to MPG mail...</h3>
<div id= "form">
<form action="?" method="POST" onsubmit="return saveScrollPositions(this);">
<input type="hidden" name="scrollx" id="scrollx" value="0" />
<input type="hidden" name="scrolly" id="scrolly" value="0" />
<fieldset>
<input type="text" id="name" name="name" placeholder="Name" />
<input type="text" id="email" name="email" placeholder="Email" />
<input type="submit" name="submit" value="Sign Up" />
</fieldset>
</form><!--End Form -->
<p id="feedback"><?php echo $feedback; ?></p>
</div><!-- End Form -->
</div><!-- End mail -->
<?php
$to = '@morrisonpg.com.au';
$subject = 'Sign Up';
$name = $_POST ['name'];
$email = $_POST ['email'];
$body = <<<EMAIL
Please add $name with the email $email to your mailing list.
EMAIL;
$header = ' From: $name ';
if($_POST){
if($name == '' || $email == ''){
$feedback = '*Please fill out all the fields';
}else {
mail($to, $subject, $body, $header);
$feedback = 'Thanks for signing up. <br /> You will receive correspondence soon!';
}
}
?>
为每个表单指定不同的名称,并在每个表单中放置一个隐藏元素,如
<input type="hidden" name="form_type" value="1" />
您应该简单地为submit按钮添加名称:
<input type="submit" name="submit" value="Sign Up" />
在PHP中:
<?php if($_POST['submit']=='Sign Up'){ /* signup code */}else{ /* other code */}?>
您正在将每个表单发送给同一个php处理程序,但没有任何提示。更多细节见我的答案