<![CDATA[ User ID and First 2 Digits of Post code for User Account No - My Forums]]> https://forums.modx.com/thread/?thread=93188 <![CDATA[User ID and First 2 Digits of Post code for User Account No]]> https://forums.modx.com/thread/93188/user-id-and-first-2-digits-of-post-code-for-user-account-no#dis-post-508954
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.]]>
bigben83 Sep 17, 2014, 01:12 AM https://forums.modx.com/thread/93188/user-id-and-first-2-digits-of-post-code-for-user-account-no#dis-post-508954
<![CDATA[Re: User ID and First 2 Digits of Post code for User Account No]]> https://forums.modx.com/thread/93188/user-id-and-first-2-digits-of-post-code-for-user-account-no#dis-post-509128 ]]> BobRay Sep 19, 2014, 09:41 PM https://forums.modx.com/thread/93188/user-id-and-first-2-digits-of-post-code-for-user-account-no#dis-post-509128 <![CDATA[Re: User ID and First 2 Digits of Post code for User Account No]]> https://forums.modx.com/thread/93188/user-id-and-first-2-digits-of-post-code-for-user-account-no#dis-post-509018 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.]]>
bigben83 Sep 17, 2014, 04:55 PM https://forums.modx.com/thread/93188/user-id-and-first-2-digits-of-post-code-for-user-account-no#dis-post-509018
<![CDATA[Re: User ID and First 2 Digits of Post code for User Account No]]> https://forums.modx.com/thread/93188/user-id-and-first-2-digits-of-post-code-for-user-account-no#dis-post-509014
$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>








]]>
BobRay Sep 17, 2014, 02:42 PM https://forums.modx.com/thread/93188/user-id-and-first-2-digits-of-post-code-for-user-account-no#dis-post-509014