We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30319
    • 406 Posts
    I'm not really a programmer, I'm trying to create a hook which will email people depending which radio button chosen:
    Formit code and form section:

    <h2>Email</h2>
    [[!Profile? &prefix=`usr.`]]
    [[!FormIt?  
    &hooks=`emailSelector,email,redirect`  
    &emailTpl=`bar.email`
    &emailSubject=`Inquiry` 
    &emailTo=`[[+emailAddresses]]`
    &emailCC=`[[+usr.email]]`
    &emailBCC=``
    &emailFromName=`[[+usr.username]]`
    &redirectTo=`72`
    &validate=`text:required:stripTags`
    ]]
    
    
    <form action="[[~[[*id]]]]" method="post" class="nice">  
    <input type="hidden" name="nospam:blank" value="" />
    
    <p>
    <label>Choose whom to email: [[!+fi.error.whom]]</label>
    <input type="hidden" name="whom[]" value="" />
    <input type="radio" name="whom[]" value="0" [[!+fi.color:FormItIsChecked=`1`]] > First Person
    
    <input type="radio" name="whom[]" value="1" [[!+fi.color:FormItIsChecked=`2`]] > Second Person
    
    <input type="radio" name="whom[]" value="2" [[!+fi.color:FormItIsChecked=`3`]] > Both People
     
    </p>
    


    Snippet code (copied from another post):

    <?php
    $group[0] = 't@barcom'; // First Person
    $group[1] = '[email protected]'; // Second Person
    $group[2] = '[email protected], [email protected]'; // Both People
    $userChoice = $hook->getValue('whom');
    $hook->setValue('emailAddresses',$group[$userChoice]);
    return true;
    


    The CC to the sender is showing [[+emailAddresses]] in the To: line and modx shows this error code:
    [2012-03-13 16:04:10] (ERROR @ /[path snipped out]/core/cache/includes/elements/modsnippet/38.include.cache.php : 11) PHP warning: Illegal offset type
    


    Revo 2.2-pl2, Formit 2.0.3

    Thank you, Tom

    This question has been answered by TomMLS. See the first response.

    [ed. note: TomMLS last edited this post 12 years, 1 month ago.]
      • 1778
      • 659 Posts
      Just a quick reply, not sure it"s the source of problem but in your '<input type="radio" ....> there a mistake in the formit validator isChecked should be
      <input type="radio" name="whom[]" value="0" [[!+fi.whom:FormItIsChecked=`1`]] >
      

      instead of
      <input type="radio" name="whom[]" value="0" [[!+fi.color:FormItIsChecked=`1`]] >
      

      To ensure a value is well sent... (in your call you sent a value if color is checked not whom ^_^)
      Hope it's enough to solve your issue
      Cheers
        • 30319
        • 406 Posts
        No, not yet, still same issues, the emailAddresses placeholder is still not being filled, the To: line still says [[+emailAddresses]] instead of real email addresses, and I still get the PHP offset error...

        Thank you, Tom
          • 1778
          • 659 Posts
          Could you try this ?
          <?php
          $group[0] = 't@barcom'; // First Person
          $group[1] = '[email protected]'; // Second Person
          $group[2] = '[email protected], [email protected]'; // Both People
          $userChoice = $hook->getValue('whom');
           $modx->log(modX::LOG_LEVEL_ERROR, 'userchoice :'.$userChoice ); // output the value of userchoice in your error log (just to be sure there is a value) you can remove this line once you have it to work
          $choice = intval($userChoice); // convert string in integer
          $hook->setValue('emailAddresses',$group[$choice]);
          return true;
          
            • 4172
            • 5,888 Posts
            I think you don't want to send whom as array, so try:

            <input type="radio" name="whom" value="2" [[!+fi.whom:FormItIsChecked=`3`]] > Both People
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 30319
              • 406 Posts
              Better than before, it's filling in a value for [[+emailAddresses]] but not properly using the array
              [2012-03-13 16:59:02] (ERROR @ /index.php) userchoice :Array
              [2012-03-13 17:00:24] (ERROR @ /index.php) userchoice :Array
                • 30319
                • 406 Posts
                Thank you Bruno...now it is putting a value into userchoice which is returned into the error log...must see why it is always using the same value each time though...
                • discuss.answer
                  • 30319
                  • 406 Posts
                  NOW it works...Thank you everyone...I put this to solved.
                  CORRECT form and snippet code shown below:

                  <p>
                  <label>Choose whom to email: [[!+fi.error.whom]]</label>
                  <input type="hidden" name="whom" value="" />
                  <input type="radio" name="whom" value="0" [[!+fi.whom:FormItIsChecked=`1`]] > First Person
                  <input type="radio" name="whom" value="1" [[!+fi.whom:FormItIsChecked=`2`]] > Second Person
                  <input type="radio" name="whom" value="2" [[!+fi.whom:FormItIsChecked=`3`]] > Both People
                  </p>
                  


                  <?php
                  $group[0] = 't@barcom'; // First Person
                  $group[1] = '[email protected]'; // Second Person
                  $group[2] = '[email protected], [email protected]'; // Both People
                  $userChoice = $hook->getValue('whom');
                   $modx->log(modX::LOG_LEVEL_ERROR, 'userchoice :'.$userChoice ); // output the value of userchoice in your error log (just to be sure there is a value) you can remove this line once you have it to work
                  $choice = intval($userChoice); // convert string in integer
                  $hook->setValue('emailAddresses',$group[$choice]);
                  return true;
                  


                  Thank you, Tom
                    • 38017
                    • 18 Posts
                    I just want to thank everyone on this thread it has allowed me to do something unique. Change email address based on a state. I just hope someone else might find this useful also.

                    // &hooks=`emailSelectorCustom,
                    // &emailTo=`[[+emailAddresses]]`
                    
                    // $stateChoice = "NE";
                    $stateChoice = $hook->getValue('state');
                    
                    $eastCoast = array("NE","NY","FL");
                    
                    // $modx->log(modX::LOG_LEVEL_ERROR, 'userchoice :'.$userChoice ); //remove this line once you have it working
                    
                    if (in_array($stateChoice, $eastCoast)) {
                    	// East Coast Email
                    	$hook->setValue('emailAddresses', '[email protected]');
                    	} else {
                    	// West Coast Email
                    	// default this email address if nothing is matched above
                    	$hook->setValue('emailAddresses', '[email protected]');
                    }
                    return true;