仅 1 个 Jquery UI Multiselect 值通过 PHPmailer 发送
我正在处理一个联系表单,该表单未正确发布我的多项选择答案。我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
更新:(PHPMailer-FE + amselect 示例)
UPDATED: ( PHPMailer-FE + amselect Example )
通常这是由于错误命名输入而导致的。我以前没有使用过多重选择,但我建议您的输入标签需要看起来像这样:
等等...
请注意,您需要在 name 属性中使用方括号来表示数组表示法。如果这样做,PHP 会将变量显示为数组。
在您的情况下(现在您已经添加了一个示例),您只需要使您的选择标签末尾有数组运算符:
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:
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:
我已经查看了您所说的正在使用的插件,现在我明白了问题所在......它有问题。
它生成的输入不适合发布到服务器,因为它们都具有相同的名称。 PHP 无法区分具有相同名称的输入(除非它们包含括号符号 - [] - 那么它们被视为数组)
我在这里模拟了一个小演示:
http://jsbin.com/upuhe/edit
使用 firebug 之类的东西检查复选框,您会看到它们都有相同的名称。
如果我在你那里,我会使用 JQuery 重命名你的插件创建的检查框,如下所示:
请参阅: http:// jsbin.com/upuhe/2/edit
这假设您将选择设置为
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
This assumes you set your select something up like
<select name='select[]' multiple='multiple'>