gpt4 book ai didi

javascript - 将单选按钮的值发布到电子邮件

转载 作者:行者123 更新时间:2023-12-03 10:34:18 24 4
gpt4 key购买 nike

我正在尝试将单选按钮中的值发送到电子邮件。这个想法是为了邀请,所以我正在寻找单选按钮值和电子邮件地址。

到目前为止,我似乎成功地将值和电子邮件发送到我的收件箱,但是,无论用户选择什么,它似乎都只发送第一个选项。

此外,在提交电子邮件和值时,我收到错误警报“发生错误 (2)”,但这些值仍然出现在我的收件箱中,因此我不确定为什么会这样做。

<div id="invitation">
<div class="container invitation">
<div id="successInv" class="alert alert-success invisible">
<strong>Thank you!</strong> We'll be in touch with more details.
</div>
<div class="row-fluid">
<div class="span7 center">
<form class="inline-form">
<input id="option1" type="radio" name="type" class="span1" value="op1" checked>
<label for="option1">Option 1</label>
<input id="option2" type="radio" name="type" class="span1" value="op2">
<label for="option2">Option 2</label>
<input id="option3" type="radio" name="type" class="span1" value="op3">
<label for="option3">Option 3</label>
<input type="email" name="email" id="invmail" class="span8" placeholder="Enter your email for an exclusive invitation" required />
<button id="invitation" class="button button-inv">Request invitation</button>
</form>
<div id="err-inv" class="error centered">Please provide a valid email address.</div>
</div>
</div>
</div>

下面的JS:

 $('#invitation').click(function () {

var error = false;
var emailCompare = /^([a-z0-9_.-]+)@([0-9a-z.-]+).([a-z.]{2,6})$/;
var email = $('input#nlmail').val().toLowerCase();
if (email == "" || email == " " || !emailCompare.test(email)) {
$('#err-inv').show(500);
$('#err-inv').delay(4000);
$('#err-inv').animate({
height: 'toggle'
}, 500, function () {
});
error = true;
}

if (error === false) {
$.ajax({
type: 'POST',
url: 'php/invitation.php',

data: {
email: $('#invmail').val(),
type: $('#type').val()
},
error: function (request, error) {
alert("An error occurred (1)");
},
success: function (response) {
if (response == 'OK') {
$('#successInv').show();
$('#invmail').val('')
} else {
alert("An error occurred (2)");
}
}
});
return false;
}
return false;
});

下面是 PHP:

<?php
include 'functions.php';
if (!empty($_POST)){
$data['success'] = true;
$_POST = multiDimensionalArrayMap('cleanEvilTags', $_POST);
$_POST = multiDimensionalArrayMap('cleanData', $_POST);
$emailTo ="yourmail@yoursite.co.uk";
$emailFrom ="contact@yoursite.co.uk";
$emailSubject = "New invitation request";
$email = $_POST["email"];
$type = $_POST["type"];
if (!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $email))
$data['success'] = false;

if($data['success'] == true){
$message = "Email: $email - Type: $type";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html; charset=utf-8" . "\r\n";
$headers .= "From: <$emailFrom>" . "\r\n";
mail($emailTo, $emailSubject, $message, $headers);
$data['success'] = true;
echo json_encode($data);
}
}

如果能帮助我确定为什么它只发送原始检查值,我们将不胜感激。

最佳答案

 <input class='radioval' type="radio" name="type" class="span1" value="op1">
<label for="option1">Option 1</label>
<input class='radioval' type="radio" name="type" class="span1" value="op2">
<label for="option2">Option 2</label>
<input class='radioval' type="radio" name="type" class="span1" value="op3">
<label for="option3">Option 3</label>

并在 AJAX 调用中进行更改

data: {
email: $('#invmail').val(),
type: $('.radioval').is(':checked').val()
},

关于javascript - 将单选按钮的值发布到电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29074630/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com