We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26931
    • 2,314 Posts
    Hi everybody,

    i’m trying to send the output of a Snippet with "&eFormOnBeforeFormParse", but i get an error when the snippet uses
    $modx->makeUrl();
    ->
    « `` is not numeric and may not be passed to makeUrl() »

    what i try to achieve is, to pass the site’s url to an eForm call which opens in a popup ( basically for "Tell a Friend" functionality). The link which opens the popup looks like this:
    <a href="[~32~]?seite=[*id*]"  onclick="return showLinkAsPopup(this);">recommend</a> 


    the Snippet [[GetSitename]]
    <?php
    if( !function_exists('eformGetSitename') ) {
    	function eformGetSitename(){
    		global $modx;
    		$site = strip_tags($_GET['seite']);
    		$url = $modx->makeUrl($site);
    		$modx->setPlaceholder('siteurl', $url);
    		return true;
    	}
    }
    return '';
    ?>

    and on ressource ID32 which opens in the popup, my two Snippet :
    [!GetSitename!]
    [!eForm? ... parameters ... &eFormOnBeforeFormParse=`eformGetSitename` !]


    in my eForm template i’ve got:
    <input name="siteurl" id="siteurl" value="[+siteurl+]"  />


    i can see that the URL is passed to my eForm template, but after submitting i get the above parse error.

    if the snippet is set up to return an other value e.g. the pagetitle, it’s working and the data will be sent with the email.

    does anyone know why that’s happening, and maybe how to solve it?

    thanks, j

    MODx Evolution 1.0.2
    eForm - 1.4.4.6
    5.0.32-Debian_7etch11-log
    PHP 5.2.12

      • 10487 MODX Staff
      • 1,535 Posts
      On your form, does your ’action’ attribute also include the seite parameter, e.g. [~[*id*]~]?seite=xx

      If not, you will be losing that value when the form is posted back to the page, either include it in the ’action’ attribute or pass it as a hidden field in your form. If you use the latter option, change your eformGetSitename() function to get the site using:
      $site= strip_tags($_REQUEST['seite']);
      $modx->setPlaceholder('seite', $site);
      
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 26931
        • 2,314 Posts
        spot on, garryn! smiley
        On your form, does your ’action’ attribute also include the seite parameter, e.g. [~[*id*]~]?seite=xx
        ->
        <form method="post" action="[~[*id*]~]?seite=[*id*]">
        ... did the trick

        thanks a lot!, j
          • 26931
          • 2,314 Posts
          ...while i’m at it, got another question...

          i tweaked the above snippet to also return the ressource alias as a placeholder:

          <?php
          if( !function_exists('eformGetSitename') ) {
          	function eformGetSitename(){
          		global $modx;
          		$site = strip_tags($_GET['seite']);
          
          $pgt = $modx->getDocument($site,'alias');
          $alias = $pgt['alias'];
          $modx->setPlaceholder('sitealias', $alias);
          
          		$url = $modx->makeUrl($site, '', '', 'full');
          		$modx->setPlaceholder('siteurl', $url);
          
          		return true;
          	}
          }
          return '';
          ?>


          when i place
          <input name="sitealias" type="hidden" value="[+sitealias+]"  />
          in my template chunk, no value will be added
          ... but when i use:
          <input name="sitealias" style="display:none;"  value="[+sitealias+]"  />
          ... it works

          does anyone know why? smiley thanks, j

            • 26931
            • 2,314 Posts
            when i place <input name="sitealias" type="hidden" value="[+sitealias+]" /> in my template chunk, no value will be added
            ... but when i use: <input name="sitealias" style="display:none;" value="[+sitealias+]" /> ... it works
            aah,of course

            <?php
            if( !function_exists('eformGetSitename') ) {
            	function eformGetSitename(&$fields,&$templates){
            		global $modx;
            		$site = strip_tags($_GET['seite']);
            
            		$pgt = $modx->getDocument($site,'alias');
            		$alias = $pgt['alias'];
            
            		$url = $modx->makeUrl($site, '', '', 'full');
            
            		$templates['tpl']=str_replace('[+display_siteurl+]',$url,$templates['tpl']);
            		$templates['tpl']=str_replace('[+display_sitealias+]',$alias,$templates['tpl']);
            		return true;
            	}
            }
            return '';
            ?>

            and
            		<input name="siteurl" type="hidden" value="[+display_siteurl+]" eform="::0::" />
            		<input name="sitealias" type="hidden"  value="[+display_sitealias+]" eform="::0::"  />
            in my template ... works as expected smiley
              • 33968
              • 863 Posts
              Hi there sharkbait smiley

              I’m having some success with your GetSitename script, thanks! But as always I’m pushing things a bit too far...

              I can successfully display, say the pagetitle which is working great. But now I want to pass one or two template variables to the form as well.

              This isn’t working:

              <?php
              if( !function_exists('eformGetSitename') ) {
              	function eformGetSitename(&$fields,&$templates){
              		global $modx;
              		$site = strip_tags($_GET['page']);
              
              		$pgt = $modx->getTemplateVar($site,'locState');
              		$locState = $pgt['locState'];
              
              		$url = $modx->makeUrl($site, '', '', 'full');
              
              		$templates['tpl']=str_replace('[+display_siteurl+]',$url,$templates['tpl']);
              		$templates['tpl']=str_replace('[+display_locState+]',$locState,$templates['tpl']);
              
              		return true;
              	}
              }
              return '';
              ?>


              In this example, the TV I am trying to send it called locState

              I don’t know much php so it’s a little trial and error for me. Do you know how I might include the TVs, and if so how might I pass multiple parameters to the form (such as pagetitle, tv1, tv2)?

              Thanks so much in advance!
                • 26931
                • 2,314 Posts
                Hi lucas,

                try:
                <?php
                if( !function_exists('eformGetSitename') ) {
                	function eformGetSitename(&$fields,&$templates){
                		global $modx;
                		$site = strip_tags($_GET['page']);
                
                		$document_tvs=$modx->getTemplateVarOutput(true, $site);
                		$locState=$document_tvs['locState'];
                
                		$url = $modx->makeUrl($site, '', '', 'full');
                
                		$templates['tpl']=str_replace('[+display_siteurl+]',$url,$templates['tpl']);
                		$templates['tpl']=str_replace('[+display_locState+]',$locState,$templates['tpl']);
                
                		return true;
                	}
                }
                return '';
                ?>


                Do you know how I might include the TVs, and if so how might I pass multiple parameters to the form (such as pagetitle, tv1, tv2)?
                you can add more of those:
                $templates['tpl']=str_replace('[+display_locState+]',$locState,$templates['tpl']);


                  • 33968
                  • 863 Posts
                  That works quite well for text-based TVs, although it doesn’t seem to return numerical or path values (eg. for postcode, or an image TV). This might be another issue altogether, but if you see any reason why this might be happening please let me know. Otherwise I will find a way around it, no need to take up more of your time smiley

                  *** Forget it, the image was being manipulated via phpThumb which is perhaps causing the issues **

                  Thanks for your help mate!
                    • 26931
                    • 2,314 Posts
                    pleasure, glad i could help smiley
                      • 33968
                      • 863 Posts
                      Me again!

                      Just wondering if it would be possible to use this snippet without eForm?

                      I would like to access TV values from the ’previous page’ in two ways:

                      - in the current page content, say as a heading (eg. [+display_pagetitle+] )
                      - inside a template for a ditto call on the current page

                      I’ve attempted the above but can’t figure out how to get modx or Ditto to parse the [+display_...+] placeholders. undecided

                      Thanks

                      Luke