开发者

Only 1 Jquery UI Multiselect value being sent through PHPmailer

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>
         开发者_Go百科   <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


UPDATED: ( PHPMailer-FE + amselect Example )

  • Demo + Source: https://so.lucafilosofi.com/only-1-jquery-ui-multiselect-value-being-sent-through-phpmailer


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>


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'>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜