We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21379
    • 3 Posts
    Hello everyone,

    I have read and read and read but can’t find anything to shed some light on my problem. What I am trying to do is create an eForm that would email the owner of a "custom" branded site based on their email address in the system. This has to be dynamic because currently we have about 80 custom websites in this system. Below is the entire snippet that I have. You will notice the email address comes from a database and I have assigned the variable $resEmail[’email’] as the email address. Is it possible to "inject" this variable into a snippet call instead of plain text? I have tried &to=`.$resEmail[’email’].`, &to=`$resEmail[’email’]`, &to=$resEmail[’email’], and nothing seems to work! Is it even possible to place variables into a snippet call before it is processed? Any help is GREATLY appreciated!

    <?php
    $blaid = $modx->documentObject;
    $parent = $modx->getParent($blaid[’id’]);
    $username = $parent[’alias’];

    $table = $modx->getFullTableName("web_users");
    $sqlEmail = $modx->db->select("id", $table, "username = ’$username’");
    $resEmail = $modx->db->getRow($sqlEmail);

    $table = $modx->getFullTableName("web_user_attributes");
    $sqlEmail = $modx->db->select("email", $table, "id = ’$resEmail[id]’");
    $resEmail = $modx->db->getRow($sqlEmail);

    if(empty($resEmail[’email’])){
    $resEmail[’email’] = "[email protected]";
    }

    switch($_POST[’insuranceType’]){
    case "auto":
    ?>
    [!eForm? &formid=`autoQuoteForm` &tpl=`autoQuoteForm` &report=`autoQuoteFormEmail` &to=`.$resEmail[’email’].` &subject=`Auto Quote Received` &from=`[email protected]` &thankyou=`46`!]
    <?
    break;
    case "property":
    ?>
    [!eForm? &formid=`propQuoteForm` &tpl=`propQuoteForm` &report=`propQuoteFormEmail` &to=`.$resEmail[’email’].` &subject=`Property Quote Received` &from=`[email protected]` &thankyou=`46`!]
    <?
    break;
    case "specialty":
    ?>
    [!eForm? &formid=`specialtyQuoteForm` &tpl=`specialtyQuoteForm` &report=`specialtyQuoteFormEmail` &to=`.$resEmail[’email’].` &subject=`Specialty Quote Received` &from=`[email protected]` &thankyou=`46`!]
    <?
    break;
    case "business":
    ?>
    [!eForm? &formid=`businessQuoteForm` &tpl=`businessQuoteForm` &report=`businessQuoteFormEmail` &to=`.$resEmail[’email’].` &subject=`Business Quote Received` &from=`[email protected]` &thankyou=`46`!]
    <?
    break;
    }
    ?>
      • 7231
      • 4,205 Posts
      You are not getting the value because you are processing the variable outside of <?php ?> tags so the server does not change it into the value.

      Try it like this:
      <?php
      $blaid = $modx->documentObject;
      $parent = $modx->getParent($blaid['id']);
      $username = $parent['alias'];
      
      $table = $modx->getFullTableName("web_users");
      $sqlEmail = $modx->db->select("id", $table, "username = '$username'");
      $resEmail = $modx->db->getRow($sqlEmail);
      
      $table = $modx->getFullTableName("web_user_attributes");
      $sqlEmail = $modx->db->select("email", $table, "id = '$resEmail[id]'");
      $resEmail = $modx->db->getRow($sqlEmail);
      
      if(empty($resEmail['email'])){
           $resEmail['email'] = "[email protected]";
      }
      
      switch($_POST['insuranceType']){
          case "auto":
          $output =  '[!eForm? &formid=`autoQuoteForm` &tpl=`autoQuoteForm` &report=`autoQuoteFormEmail` &to=`'.$resEmail['email'].'` &subject=`Auto Quote Received` &from=`[email protected]` &thankyou=`46`!]';
          break;
          case "property":
           $output =  '[!eForm? &formid=`propQuoteForm` &tpl=`propQuoteForm` &report=`propQuoteFormEmail` &to=`'.$resEmail['email'].'` &subject=`Property Quote Received` &from=`[email protected]` &thankyou=`46`!]';
          break;
          case "specialty":
          $output =  '[!eForm? &formid=`specialtyQuoteForm` &tpl=`specialtyQuoteForm` &report=`specialtyQuoteFormEmail` &to=`'.$resEmail['email'].'` &subject=`Specialty Quote Received` &from=`[email protected]` &thankyou=`46`!]';
          break;
          case "business":
          $output =  '[!eForm? &formid=`businessQuoteForm` &tpl=`businessQuoteForm` &report=`businessQuoteFormEmail` &to=`'.$resEmail['email'].'` &subject=`Business Quote Received` &from=`[email protected]` &thankyou=`46`!]';
          break;
      }
      
      return $output;
      ?>


      Although it may be even better to use the $modx->runSnippet api call and execute eForm directly in the snippet.
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don&#39;t know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 21379
        • 3 Posts
        OMG! I have been staring at that for SOOO long. THANKS! IT worked!

        I also had never thought of the snippet API, so that would run the eForm snippet inside of the main snippet? For lack of better words, embedding snippets?
          • 34017
          • 898 Posts
          yeah you can have a snippet run other snippets. it’s very handy.

          I think this code might work:
          <?php
          //default parameters for all switches
          $params = array(
              'to'        => $resEmail['email'],
              'from'      => '[email protected]',
              'thankyou'  => '46',
              );
          
          switch($_POST['insuranceType']){
              
              case "auto":
                  $params['formid'] = 'autoQuoteForm';
                  $params['tpl']    = 'autoQuoteForm';
                  $params['email']  = 'autoQuoteFormEmail';
                  $params['subject']= 'Auto Quote Received';
                  break;
                  
              case "property":
                  $params['formid'] = 'propQuoteForm';
                  $params['tpl']    = 'propQuoteForm';
                  $params['email']  = 'propQuoteFormEmail';
                  $params['subject']= 'Property Quote Received';
                  break;
                  
              case "specialty":
                  $params['formid'] = 'specialtyQuoteForm';
                  $params['tpl']    = 'specialtyQuoteForm';
                  $params['email']  = 'specialtyQuoteFormEmail';
                  $params['subject']= 'Speciality Quote Received';
                  break;
                  
              case "business":
                  $params['formid'] = 'businessQuoteForm';
                  $params['tpl']    = 'businessQuoteForm';
                  $params['email']  = 'businessQuoteFormEmail';
                  $params['subject']= 'Business Quote Received';
                  break;
          }
          
          $output = $modx->runSnippet('eForm', $params);
          
          return $output;
          
          ?>
          


            Chuck the Trukk
            ProWebscape.com :: Nashville-WebDesign.com
            - - - - - - - -
            What are TV's? Here's some info below.
            http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
            http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008
            • 21379
            • 3 Posts
            Interesting. I’ll check this out when I get to the office tomorrow. Thanks!