仅 1 个 Jquery UI Multiselect 值通过 PHPmailer 发送

发布于 2024-10-19 04:35:36 字数 1509 浏览 2 评论 0原文

我正在处理一个联系表单,该表单未正确发布我的多项选择答案。我正在使用 PHPMailer-FE 发送表单结果。 PHPMailer-FE 包含 php 类文件、配置脚本和 TPL 文件。

我在使用 Ryan Cramer 的 jquery.amselect.js 小部件时遇到问题,其中电子邮件中发送的是“Array”一词,而不是逗号分隔的选定值列表。

以下是 amselect 小部件的实际操作示例: http://www.ryancramer.com/projects/asmselect/examples/example1.html

这是 HTML:

   <select style="width: 200px !important;" id="cards" name="cards[]" multiple="multiple" title="Choose All That Apply" >
            <option value="Visa">Visa</option>
            <option value="Mastercard">Mastercard</option>
            <option value="Amex">American Express</option>
            <option value="Discover">Discover</option>
            <option value="Diners">Diner's Club</option>
            <option value="JCB">JCB</option>
            <option value="Visa-Delta">Visa Debit/Delta</option>
            <option value="Switch-Maestro">Switch/Maestro</option>
            <option value="solo">solo</option>
            <option value="Visa-Electron">Visa Electron</option>
          </select>

感谢 @aSeptik,我现在明白要解决这个问题,我们可以使用 implode 标签。在他的工作演示中,php 包含在 HTML 文件的顶部:

$message .= implode(', ',$_POST['cards']);

我尝试在我的 TPL 或类文件中使用 implode 标签,但没有成功。

任何帮助将不胜感激,我正在努力解决这个问题。非常感谢!问候,诺兰

I am working on a contact form that is not posting my multiple selection answers correctly. I am using PHPMailer-FE to send the form results. PHPMailer-FE contains a php class file, configuration script, and TPL file.

I am encountering a problem with Ryan Cramer's jquery.amselect.js widget where the word "Array" is being sent in the email instead of a comma separated list of selected values.

Here is an example of the amselect widget in action:
http://www.ryancramer.com/projects/asmselect/examples/example1.html.

Here's the HTML:

   <select style="width: 200px !important;" id="cards" name="cards[]" multiple="multiple" title="Choose All That Apply" >
            <option value="Visa">Visa</option>
            <option value="Mastercard">Mastercard</option>
            <option value="Amex">American Express</option>
            <option value="Discover">Discover</option>
            <option value="Diners">Diner's Club</option>
            <option value="JCB">JCB</option>
            <option value="Visa-Delta">Visa Debit/Delta</option>
            <option value="Switch-Maestro">Switch/Maestro</option>
            <option value="solo">solo</option>
            <option value="Visa-Electron">Visa Electron</option>
          </select>

Thanks to @aSeptik, I now understand to fix the issue we can use the implode tag. In his working demo the php is included at the top of the HTML file:

$message .= implode(', ',$_POST['cards']);

I have tried using the implode tag in my TPL or class file with no success.

Any assistance would be much appreciated I am working very hard to fix this problem. Many thanks! Regards, Nolan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

停滞 2024-10-26 04:35:36

通常这是由于错误命名输入而导致的。我以前没有使用过多重选择,但我建议您的输入标签需要看起来像这样:

<input type="checkbox" name="myBox[]" />
<input type="checkbox" name="myBox[]" />
<input type="checkbox" name="myBox[]" />

等等...

请注意,您需要在 name 属性中使用方括号来表示数组表示法。如果这样做,PHP 会将变量显示为数组。

在您的情况下(现在您已经添加了一个示例),您只需要使您的选择标签末尾有数组运算符:

<select class="mydrop" name="cards-accepted[]" multiple="multiple" size="5">
</select>

Usually this is caused by incorrectly naming your inputs. I haven't used multi select before but I would sudggest that your input tags need to look something like this:

<input type="checkbox" name="myBox[]" />
<input type="checkbox" name="myBox[]" />
<input type="checkbox" name="myBox[]" />

etc...

Notice that you need to have square brackets for array notation in the name attribute. PHP will show the variable as an array if you do that.

In your case (now you've added an example) You just need to make your select tag have the array operator at the end:

<select class="mydrop" name="cards-accepted[]" multiple="multiple" size="5">
</select>
眼波传意 2024-10-26 04:35:36

我已经查看了您所说的正在使用的插件,现在我明白了问题所在......它有问题。

它生成的输入不适合发布到服务器,因为它们都具有相同的名称。 PHP 无法区分具有相同名称的输入(除非它们包含括号符号 - [] - 那么它们被视为数组)

我在这里模拟了一个小演示:

http://jsbin.com/upuhe/edit

使用 firebug 之类的东西检查复选框,您会看到它们都有相同的名称。

如果我在你那里,我会使用 JQuery 重命名你的插件创建的检查框,如下所示:

请参阅: http:// jsbin.com/upuhe/2/edit

$("select").multiselect()
  .each(function(){

    var selectEl = $(this);        
    var selectElName = selectEl.attr("name")

    selectEl.multiselect("widget")
      .find("input[type=checkbox]")
        .attr({ name: selectElName });
})

这假设您将选择设置为

I have taken a look at the plugin you said you were using and I now see what the problem is... it's buggy.

The inputs it generates are no good for posting to a server because they all have the same name. PHP has no way of distinguishing between inputs with the same name (unless they include the bracket notation - [] - then they are treated as arrays)

I mocked up a little demo here:

http://jsbin.com/upuhe/edit

Use something like firebug to inspect the checkboxes and you will see that they all have the same name.

If I where you I would use JQuery to rename the chekboxes that your plugin creates like this:

see: http://jsbin.com/upuhe/2/edit

$("select").multiselect()
  .each(function(){

    var selectEl = $(this);        
    var selectElName = selectEl.attr("name")

    selectEl.multiselect("widget")
      .find("input[type=checkbox]")
        .attr({ name: selectElName });
})

This assumes you set your select something up like <select name='select[]' multiple='multiple'>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文