Search

I'm having some trouble with multiple recipients. I know that they're suppose to be comma separated but I thought I could do the following:

<label>Recipients</label>
<p>
    <select multiple="multiple" name="fields[recipients]">
        <option value="username1">Username 1</option>
        <option value="username2">Username 2</option>
        <option value="username3">Username 3</option>
    </select>                           
</p>

And have my hidden fields:

<input name="send-email[recipient]" value="fields[recipients]" type="hidden" />
<input name="send-email[sender-email]" value="fields[email]" type="hidden" />
<input name="send-email[sender-name]" value="fields[name]" type="hidden" />
...

At the moment if I print out the $_POST, it shows that only one username is the value of the recipients -- even though I've selected more than one.

I know I could make the value have a comma separated variable with JavaScript, but I'm wondering if there's a Native way to do this.

Thanks.

You need [] on the end of your field's name:

<select multiple="multiple" name="fields[recipients][]">

That will give you the array in the $_POST. But, the Event isn't going to listen to it as it expects comma separated usernames, not an array.

Thanks Alistair. I've added the []

It's not pretty but this works:

public function load(){
    if(isset($_POST['action']['save-message'])){
        if($_POST['fields'] && $_POST['fields']['recipients']) 
            $_POST['send-email']['recipient'] = join(',', $_POST['fields']['recipients']);
        return $this->__trigger();
    }
}

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details