On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • Can someone help me, I'm trying to parse the first two digits of a Users Postcode and add to beginning of their User ID.

    I have a snippet called [[userID]]
    $digits = $modx->getOption('zip',$scriptProperties,false);
    if (empty($zip)) return '';
    
    $firstdigits = substr($digits, -2); 
    print $firstdigits;


    then I am calling this in to a user profile with the following
    [[!Profile]]
    <table>
    <tr><th style="width: 150px"><b>Customer Account ID:</b></th><td>[[userID]][[+id]]</td></tr>
    </table>


    It isn't returning any digits from the zip code, only showing the userID number.
    Am I doing something wrong when calling the zip code into the array.
    • First, I think you want this:

      $firstdigits = substr($digits, 0, 2); 


      Second, you're not sending the 'zip' field as a snippet property, so it's not in the $scriptProperties array.

      Assuming that Profile is setting the 'zip' placeholder, you should be able to get it this way:

      $digits = $modx->getPlaceholder('zip');


      or you could try putting the placeholder in the snippet tag:

      <tr><th style="width: 150px"><b>Customer Account ID:</b></th><td>[[userID? &zip=`[[+zip]]`]][[+id]]</td></tr>








        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
      • Thanks Bob,
        the following works manually
        $digits = '7260';
         
        $firstdigits = substr($digits, 0, 2); 
        print $firstdigits;


        the result is '72' but soon as I change
        $digits = '7260';

        to
        $digits = $modx->getPlaceholder('zip');

        all I get is a '0'.
        I can put the placeholder in the snippet tag and can call the zip in with print $zip but soon as I put into the $firsdigits I either get '0' or nothing.

        Thanks for your help.
        • The Profile snippet should be setting that placeholder. Be sure the Profile tag is at the top of the page so it executes first.
            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