We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36571
    • 145 Posts
    Hey all,

    I have a problem, which I thought would be straightforward to handle, but for some reason I can’t get it to work properly.

    I want to create a recommendation link that registered users can share, and when someone comes to the site through that link it is recorded. The problem at the moment is building the link!

    I have modifided the standard websignup.inc.php slightly to output the following when a user signs up
    <a href="http://www.chollocity.com/?ref=<?php echo $key; ?>">Use this link to invite friends</a>


    But $key just refuses to be output. Anyone got any ideas?

    Thanks
      • 3749
      • 24,544 Posts
      All PHP in MODx has to be in snippets. You’d need to create a snippet to return the value, then use a snippet tag where your PHP code is.
        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
        • 12379
        • 460 Posts
        Snippet would then be:

        <?php
        $output = ’’;
        $output = ’<a href=\"http://www.chollocity.com/?ref=’ . $key . ’\">Use this link to invite friends</a>’;
        return $output;
        ?>

          Mostly harmless.
          • 4041
          • 788 Posts
          1. Reverse any changes you made to the websignup.inc.php file.

          2a. Create a new plugin named "Webuser_ref_link" (without the quotes) with the code below (note the <?php tag is there for highlighting purposes only and should not be included in the plugin).

          <?php  // do not include this line
          // Handle event
          $e = &$modx->Event;
          switch ($e->name) {
          
          case 'OnWebSaveUser':
          if($mode =='new'){
              $webuser_ref_string ='<a href="http://www.chollocity.com/?ref='.$userid.'">Use this link to invite friends</a>';
              $modx->setPlaceholder('Webuser_ref_link', $webuser_ref_string);
              // add the placeholder below to your signup form notification template in the spot where 
              // you want the string to print:
              // [+Webuser_ref_link+]
          }
          break;
          
          default: '';
          return;
          }


          2b. On the System Events tab, make sure and add a check beside "OnWebSaveUser". Click Save.

          3. Now just add the placeholder [+Webuser_ref_link+] to the signup notification section of the template you are using. I modified the websignup.inc.php file around line 496 just to make sure the concept worked, but a better method would be to create a new chunk with the signup template and modify. The chunk method would allow easier future upgrades.
          ex:
             <hr>
              <!-- notification section -->
              <span style="font-weight:bold;">Signup completed successfully</span><br />
              Your account was successfully created.<br />
              A copy of your signup information was sent to your email address.<br /><br />
              <p>[+Webuser_ref_link+]</p>
              <?php 
              $t = ob_get_contents();
            

            xforum
            http://frsbuilders.net (under construction) forum for evolution
            • 36571
            • 145 Posts
            @BobRay & hotdiggity: The code was changed directly in websignup.inc.php, not the actual template. Thus no need to create a snippet.

            @Breezer: Works like a charm! Thank you. I knew I was approaching it from the wrong angle.