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

    So I'm working on a snippet that does something very simply (and hopefully elegantly): A selectable-recipient email form where the recipients are defined and edited in a CMP, all while protecting the e-mail address from being exposed to the internet in the html code.

    I'm trying to develop something useful - so the structure is based on the infamous 'doodles' tutorial. I've successfully modified the schema etc. and it's working beautifully, but in implementing the functional end of things I need help understanding how to query my extra's table using the xpdo model that I have setup.

    The Gist:
    The user selects the recipient.
    <select id="selectRecipient">
       <option value="21">Tom (Director)</option>
       <option value="22">Dick (Maintenance)</option> 
       <option value="23">Harry (Barber)</option>
    </select>
    


    The Snippet catches the form data, and I need to turn the value (the row id) into an e-mail address:
    Table Rows consist of 4 fields: id, name, title, email

    $recipent = //Mysterious xPDO Query that returns email address from the row id
    ...
    $modx->mail->address('to','$recipient');
    ...
    


    I know this is *really* simple stuff, but I appreciate any help. (And I'll promise to share when I get it working.) [ed. note: anablepo last edited this post 13 years, 10 months ago.]
      • 3749
      • 24,544 Posts
      If I'm understanding you, I think you want something like this:

      $user = $modx->getObject('modWhateverYourObjectIs', $id);
      
      if ($user) {
          $email = $user->get('email');
      }
      


        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 1441
        • 61 Posts
        Thanks BobRay.

        I'm afraid I'm stupider than I thought, so I'll give you as much helpful detail as I can.

        Below is my current snippet. It's nearly identical to the Doodles tutorial, but with the names of the bit that I am working on. I've tried adapting your code above - but I'm just at a loss for syntax and terminology.

        <?php
        $abm = $modx->getService('abmail','abMail',$modx->getOption('abmail.core_path',null,$modx->getOption('core_path').'components/abmail/').'model/abmail/',$scriptProperties);
        if (!($abm instanceof abMail)) return '';
         
        /* setup default properties */
        $tpl = $modx->getOption('tpl',$scriptProperties,'rowTpl');
        $sort = $modx->getOption('sort',$scriptProperties,'name');
        $dir = $modx->getOption('dir',$scriptProperties,'ASC');
        
        /* iterate */
        $output = '';
        
        foreach ($abmail as $abmails) {
            $abmailsArray = $abmails->toArray();
            $output .= $abm->getChunk($tpl,$abmailsArray);
        }
        
        return $output;
        


        For the purposes of my learning this, and eventually using it in further scripting, my wish is to create a new snippet, that will accept one variable: the row 'id'; and it'll just return the value of the 'email' field.

        (thanks SO much for your patience and help.)
          • 4172
          • 5,888 Posts
          you can try this snippet (getDBfield):

          <?php
          $packagname = $modx->getOption('packagename', $scriptProperties, '');
          $classname = $modx->getOption('classname', $scriptProperties, '');
          $returnfield = $modx->getOption('returnfield', $scriptProperties, '');
          $output = '';
          
          if (!empty($classname)) {
              if (!empty($packagename)) {
                  $modx->addPackage($packagename, $modx->getOption('core_path') . 'components/' . $packagename . '/model/');
              }
          
              unset($scriptProperties['packagename'], $scriptProperties['classname'], $scriptProperties['returnfield']);
          
              $c = $modx->newQuery($classname);
          
              foreach ($scriptProperties as $searchfield => $value) {
                  $c->where(array($searchfield => $value));
              }
          
              if ($object = $modx->getObject($classname, $c)) {
                  $output = $object->get($returnfield);
              }
          }
          
          
          return $output;
          


          [[getDBfield? &packagename=`yourpackage` &classname=`yourclass` &returnfield=`email` &id=`yourobjectid`]]
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!