admin管理员组文章数量:1122832
HTML of form is given below
<?php
for($i=$start;$i < $end ;++$i)
{
if($emails[$i]!=""){
$userId=$emails[$i]['ID'];
$user_info = get_users($userId);
echo"<tr class='iedit alternate'>
<td class='name column-name' style='border:1px solid #DBDBDB;padding-left:13px;'><input type='checkbox' id='haet_mail_test_address' name='ckboxs[]' value='".$emails[$i]['user_email']."'> ".$emails[$i]['user_email']."</td>";
echo "<td class='name column-name' style='border:1px solid #DBDBDB;'> ".$user_info->user_login."</td>";
echo "</tr>";
}
}
?>
<button class="button-primary" id="haet_mail_test_submit" name="submit" type="submit">Send Email</button>
<div id="haet_mail_test_sent" class="haet-mail-dialog" title="<?php _e('Email sent','wp-html-mail'); ?>">
<p>
<?php _e('Your message has been sent.','wp-html-mail'); ?>
</p>
below my Javascript code
$('#haet_mail_test_submit').click(function(){
var checkbox = $('#haet_mail_test_address').val();
$.post(ajaxurl, { 'action':'haet_mail_send_test', 'checkbox':checkbox} , function(response) {
$( "#haet_mail_test_sent" ).dialog({
dialogClass: "no-close",
modal: true,
buttons: [
{
text: "OK",
click: function() {
$( this ).dialog( "close" );
}
}
]
});
});
});
AJAX function is given below
function send_test() {
$email= $_POST['checkbox'];
echo $email;
wp_mail( $email, ''.$email.'');
wp_die();
}
I am new on Wordpress so how I can send the checkbox values to wp_mail
HTML of form is given below
<?php
for($i=$start;$i < $end ;++$i)
{
if($emails[$i]!=""){
$userId=$emails[$i]['ID'];
$user_info = get_users($userId);
echo"<tr class='iedit alternate'>
<td class='name column-name' style='border:1px solid #DBDBDB;padding-left:13px;'><input type='checkbox' id='haet_mail_test_address' name='ckboxs[]' value='".$emails[$i]['user_email']."'> ".$emails[$i]['user_email']."</td>";
echo "<td class='name column-name' style='border:1px solid #DBDBDB;'> ".$user_info->user_login."</td>";
echo "</tr>";
}
}
?>
<button class="button-primary" id="haet_mail_test_submit" name="submit" type="submit">Send Email</button>
<div id="haet_mail_test_sent" class="haet-mail-dialog" title="<?php _e('Email sent','wp-html-mail'); ?>">
<p>
<?php _e('Your message has been sent.','wp-html-mail'); ?>
</p>
below my Javascript code
$('#haet_mail_test_submit').click(function(){
var checkbox = $('#haet_mail_test_address').val();
$.post(ajaxurl, { 'action':'haet_mail_send_test', 'checkbox':checkbox} , function(response) {
$( "#haet_mail_test_sent" ).dialog({
dialogClass: "no-close",
modal: true,
buttons: [
{
text: "OK",
click: function() {
$( this ).dialog( "close" );
}
}
]
});
});
});
AJAX function is given below
function send_test() {
$email= $_POST['checkbox'];
echo $email;
wp_mail( $email, ''.$email.'');
wp_die();
}
I am new on Wordpress so how I can send the checkbox values to wp_mail
Share Improve this question edited Jul 6, 2018 at 5:24 Evince Development 1236 bronze badges asked Jul 6, 2018 at 5:08 Shashikant KalawatiaShashikant Kalawatia 13 bronze badges1 Answer
Reset to default 0First you need to add a class for all checkbox as having same id for multiple items is not recommended
<input type='checkbox' class="new_class" id='haet_mail_test_address' name='ckboxs[]' value='".$emails[$i]['user_email']."'>
Now we to change the way you are getting the values from checkbox
Change
var checkbox = $('#haet_mail_test_address').val();
To
var checkbox = $(".new_class:checkbox:checked").map(function(){
return $(this).val();
}).get();
console.log(checkbox); // check if you are getting the values here
Now in "checkbox" you will get an array of selected checkbox values. Now you can pass it to the ajax function as data
本文标签: ajaxHow to send the checkbox value to email
版权声明:本文标题:ajax - How to send the checkbox value to email 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736293930a1929248.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论