0

我正在构建一个站点,管理员需要能够通过复选框选择多个数据库条目(客户端)。一旦选择了相关客户,他们可以单击一个按钮,将他们重定向到一个页面,现在可以只为选定的客户撰写电子邮件。我的复选框设置如下:

<input name = 'checked_residents' value='1' id = '1' type='checkbox' />
<input name = 'checked_residents' value='2' id = '2' type='checkbox' />
<input name = 'checked_residents' value='3' id = '3' type='checkbox' />

然后我有一个按钮 (id = 'mail_selected'),当单击它时,它能够构造一个包含所选复选框的所有 id 的数组。请参见下面的代码:

$('#mail_selected').click(function(event) {
    $(':checkbox[name="checked_residents"]:checked');
    var selectedID = [];
        $(':checkbox[name="checked_residents"]:checked').each (function () {
            var tempStr = this.id;
            selectedID.push(tempStr);
        });     
});

我的问题是我需要将 selectedID 数组发送到我的 php 文件“mailer_client.php”,但我需要立即重定向到该页面,并使用来自相应 ID 的所有电子邮件填充我的“电子邮件收件人”输入字段。

我意识到可能很难理解我到底想要做什么......我不确定自己。请询问有关该问题的任何内容是否不清楚。

4

1 回答 1

1

如果您将复选框的名称更改为数组,如下所示:

<input name = 'checked_residents[]' value='1' id = '1' type='checkbox' />
<input name = 'checked_residents[]' value='2' id = '2' type='checkbox' />
<input name = 'checked_residents[]' value='3' id = '3' type='checkbox' />

那么您将在 PHP 中将它们作为数组接收,$_REQUEST['checked_residents']并且不需要您当前的代码来自己构建数组并发送它。

然后,您可以按如下方式填写电子邮件:

foreach ($_REQUEST['checked_residents'] as $val) {
   $email_to .= get_email_for_id($val) . ' , ';
}
于 2012-10-10T20:58:33.660 回答