我当前正在创建一个虚拟站点,并希望在一页上创建多个表单。
因此,当您单击每个服务时,您可以发送表格以请求报价。我得到的第一个表格工作正常,但是,当我发送第二个表格时,它只是发送第一个表格中的数据?
对于第二种形式,我只是将ID替换为contactform2,而不是如下所示的contactform。
public abstract class Party
{
public Party()
{
Names = new List<Name>();
}
public int PartyId { get; set; }
public PartyType PartyType { get; set; }
public string Comment { get; set; }
}
public class Person : Party
{
public Person()
{
}
public Gender Gender { get; set; }
public DateTime Birthday { get; set; }
public TaxIdentificationNumber TaxIdentificationNumber { get; set; }
}
public class LegalOrganization : Organization
{
public LegalOrganization()
{
}
public DateTime RegistrationDate { get; set; }
public bool IsProfitable { get; set; }
public TaxIdentificationNumber TaxIdentificationNumber { get; set; }
}
public class TaxIdentificationNumber
{
public int TaxIdentificationNumberId { get; set; }
public string Number { get; set; }
public DateTime IssueDate { get; set; }
public int PartyId { get; set; }
public Party Party { get; set; }
}
对于第二种形式,我只是将ID替换为contactform2
<div id="registerpremium" class="modal fade">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header col-md-12">
<img class=" logo_h modallogo" src="img/logo.svg">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body signupmessage">
<img src="img/marketing.svg" alt="" class="img-fluid modalicon">
<h3 class="col-md-12 formtext py-4">eCommerce Premium</h3>
<p class="text-center">Please fill in the form below, we will then send you an email to confirm where to send your products.</p>
<form id="contactform" method="post" name="contactform" onsubmit="return false;">
<div class="form-group pt-3">
<label class="sr-only pt-5" for="name">Name</label>
<input type="text" class="form-control form-control-danger form-control-lg" name="name" id="Name" placeholder="Name*">
</div>
<div class="form-group">
<label class="sr-only" for="mail">Email</label>
<input type="email" class="form-control form-control form-control-lg" name="email" id="mail" placeholder="Email*">
</div>
<div class="form-group">
<label class="sr-only" for="mail">Phone Number</label>
<input type="phone" class="form-control form-control form-control-lg" name="phone" id="phone" placeholder="Phone Number">
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<input type="checkbox" id="gdpr" name="gdpr" class="form-control md-textarea"></textarea>
<label for="gdpr" name="gdprlabel">I have read and consent to my data being collected as outlined in the <a href="test" target="_blank" class="disclaimerLink">Disclaimer</a></label>
</div>
</div>
</div>
<div class="modal-footer py-4">
<button type="submit" class="button button-header bg">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div>
第二种形式的PHP(如果您删除了第2种形式的联系后联系表)。我知道第一个表格发送的原因是因为我在主题,标题等中使用了test而不是test2。
$('#contactform2').validate({
rules: {
name: {
required: true
},
email: {
required: true,
email: true
},
gdpr: {
required: true
}
},
errorPlacement: function(){
return false;
},
submitHandler: function(){
var contactform = $('#contactform2').serialize();
$.ajax({
type: "POST",
url: 'ajax.php',
data: {
contactform: contactform
},
success: function(data){
$('#contactform2').hide();
$('.signupmessage').html('<p id="successmessage">' + data + '</p>');
},
error: function(xhr,textStatus,err){
console.log("readyState: " + xhr.readyState);
console.log("responseText: "+ xhr.responseText);
console.log("status: " + xhr.status);
console.log("text status: " + textStatus);
console.log("error: " + err);
}
});
}
});
我的第二个表单html
<?php
if (isset($_POST['contactform2'])) {
parse_str($_POST['contactform2'], $contactformData);
$name = $contactform2Data['name'];
$email = $contactform2Data['email'];
$phone = $contactform2Data['phone'];
$to = 'hello@samuelrhys.com'; //change to desired recepient
$subject = "test2";
$message = "test2". "\n" .$name. "\n" .$email. "\n" .$phone. "\n" .$message;
$headers = "test2" . "\r\n"; //change domain to that of Poppyfields
$result = mail($to, $subject, $message, $headers);
if ($result) {
echo "Thanks for contacting us, we'll be in touch soon!";
} else {
echo "Uh oh. We couldn't deliver your request at this time.";
}
}
?>
答案 0 :(得分:0)
您需要在HTML中更改name
标记值,才能从PHP访问访问请求!