We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13115
    • 15 Posts
    Is there a way to use checkboxes with mailselector instead of a select list? For my use case, the end user should be able to choose from a list of items they’re interested in, and different people get notified of the user’s interest. Any thoughts on how I might do this?

    Thanks,

    Isaac
      • 36699
      • 8 Posts
      I to am looking to do this - any help/suggestions would be very much appreciated.
        • 36699
        • 8 Posts
        I think I’ve figured this one out.

        For anyone interested here’s what I did:

        First up, use &sendirect=`1` instead of &mailselector.  You’ll see why in a tick.

        Next build a multiselect with the name of ’email’ and the value of each email address you want to use.  This is what will get used by &sendirect. 

        Create a wee php snippet (call it whatever) which uses the implode function to break up the mutilselect array.  By no stretch of the imagination have I any real clue about php.  The following works (for me) but please feel free to improve/enhance:
        <?php
        function fix_address( &$fields ){
        		$email_address = implode(",", $fields[email]);
        		$fields['email']= $email_address;
        		return true;
        	}
        return '';
        ?>
        


        Then call the snippet with the &eFormOnBeforeMailSent event like so:
        [!fix_address!]
        [!eForm? &formid=`contact_form` &sendirect=`1` &eFormOnBeforeMailSent=`fix_address` &tpl=`contact_form_tpl` &report=`contact_form_report` &thankyou=`contact_form_thanks` &subject=`Subject`!]
        


        Apologies if this has been done/covered somewhere before, but I certainly couldn’t find any reference to it.

        Enjoy!
          • 13115
          • 15 Posts
          That’s far better than what I ended up doing -- I hacked eform.inc.php and changed around line 417 to allow for a single or multi-select. Actually, I didn’t test using a value from a select box, but a single value from a set of checkboxes worked. Here’s the code I used (in case someday someone in charge wants to look at it and maybe integrate it into eform):

          Original
          if ($mselector && $fields[$mselector]) {
          	$i = (int)$fields[$mselector];
          	$ar = explode(",",$to);
          	if ($i>0) $i--;
          	if ($ar[$i]) $to = $ar[$i];
          	else $to = $ar[0];
          }
          


          What I changed it to
          if ($mselector && $fields[$mselector]) {
          	$mArr = $fields[$mselector];
          	$toPoss = explode(",",$to);
          	$toArr = array();
          	
          	foreach($mArr as $m)
          		$toArr[] = $toPoss[(int)$m];
          		
          	if(sizeof($toArr) > 0)
          		$to = implode(',',$toArr);
          }