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

    So I am writing a script and I want to pass some variables to the next page. My understanding with makeUrl is that it can be used like so:

    $url = $modx->makeUrl(25, '', array('hello' => 'world'));


    or

    $url = $modx->makeUrl(25, '', 'hello=world');


    My problem is I need to pass multiple values, which I would assume you use the array as shown above although I cant find any documentation on this? I assume it would go something like this:

    $url = $modx->makeUrl(25, '', array('hello' => 'world', 'foo' => 'bar'));


    Well this is all fine and dandy but the values of the variables are dynamic in my code so what I need to have is something along the lines of:

    $url = $modx->makeUrl(25, '', array('hello' => $world, 'foo' => $bar));


    Which does not work...nor does even a more simple:

    $url = $modx->makeUrl(25, '', 'hello='.$world);


    I even tried:

    $url = $modx->makeUrl(25, '', 'hello={$world}');


    Which just returned 'hello={$world}' in the url.

    Any suggestions on how to solve my problem?

    After this I am using:

    $modx->sendRedirect($url);


    To re-directs to the correct page.

    Thanks in advance!

    Matt

    This question has been answered by cleanboy. See the first response.

      • 4172
      • 5,888 Posts
      shouldn't make a difference, if you have

      $url = $modx->makeUrl(25, '', array('hello' => 'world', 'foo' => 'bar'));


      or

      $world = 'world';
      $bar = 'bar';
      $url = $modx->makeUrl(25, '', array('hello' => $world, 'foo' => $bar));


      makes it?

        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 42596
        • 45 Posts
        This doesn't work for me unfortunately...

        The way I am getting values for my variables is by using the following:

        $title = $modx->runSnippet('getCarVars', array('get'=>'pagetitle'));
            $price = $modx->runSnippet('getCarVars', array('get'=>'price'));
            $img = $modx->runSnippet('getCarVars', array('get'=>'img'));


        The snippet getCarVars looks like this:

        $output = "";
        
            switch($get){
                case "pagetitle":
                    $output .= $_GET['pagetitle'];
                    break;
                case "price":
                    $output .= $_GET['price'];
                    break;
                case "img":
                    $output .= $_GET['carimage'];
                    break;
            }
            
            return $output;


        And my final makeURL is:

        $url = $modx->makeUrl(17,'',array('pagetitle' => $title, 'price' => $price, 'carimage' => $img));


        Which returns the url: http://wheeldeal.co.nz/thank-you!?pagetitle=%3Cbr+%2F%3E%0A%3Cb%3ENotice%3C%2Fb%3E%3A++Undefined+index%3A+pagetitle+in+%3Cb%3E%2Fvar%2Fwww%2Fvhosts%2Fwheeldeal.co.nz%2Fhttpdocs%2Fcore%2Fcache%2Fincludes%2Felements%2Fmodsnippet%2F27.include.cache.php%3C%2Fb%3E+on+line+%3Cb%3E9%3C%2Fb%3E%3Cbr+%2F%3E%0A&price=%3Cbr+%2F%3E%0A%3Cb%3ENotice%3C%2Fb%3E%3A++Undefined+index%3A+price+in+%3Cb%3E%2Fvar%2Fwww%2Fvhosts%2Fwheeldeal.co.nz%2Fhttpdocs%2Fcore%2Fcache%2Fincludes%2Felements%2Fmodsnippet%2F27.include.cache.php%3C%2Fb%3E+on+line+%3Cb%3E12%3C%2Fb%3E%3Cbr+%2F%3E%0A&carimage=%3Cbr+%2F%3E%0A%3Cb%3ENotice%3C%2Fb%3E%3A++Undefined+index%3A+carimage+in+%3Cb%3E%2Fvar%2Fwww%2Fvhosts%2Fwheeldeal.co.nz%2Fhttpdocs%2Fcore%2Fcache%2Fincludes%2Felements%2Fmodsnippet%2F27.include.cache.php%3C%2Fb%3E+on+line+%3Cb%3E15%3C%2Fb%3E%3Cbr+%2F%3E%0A

        Translated for one of the variables it says:



        <b>Notice</b>: Undefined index: carimage in <b>/var/www/vhosts/wheeldeal.co.nz/httpdocs/core/cache/includes/elements/modsnippet/27.include.cache.php</b> on line <b>15</b>


        Which doesnt make sense to me because if i just output the variables onto the page, before putting it into makeUrl or re-directing then it puts out the correct values. I dont see why its different in makeUrl.
          • 4172
          • 5,888 Posts
          this doesn't have anything todo with the makeUrl - method.
          You get an eNotice, because of trying to get values of arrays with undefined keys

          try getReqParam:

          /**
           * getReqParam
           *
           * Copyright 2010 by Shaun McCormick <[email protected]>
           *
           * getReqParam is free software; you can redistribute it and/or modify it under
           * the terms of the GNU General Public License as published by the Free Software
           * Foundation; either version 2 of the License, or (at your option) any later
           * version.
           *
           * getReqParam is distributed in the hope that it will be useful, but WITHOUT
           * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
           * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
           * details.
           *
           * You should have received a copy of the GNU General Public License along with
           * getReqParam; if not, write to the Free Software Foundation, Inc., 59 Temple
           * Place, Suite 330, Boston, MA 02111-1307 USA
           *
           * @package getreqparam
           */
          /**
           * Returns a parameter from the php request object or other globals.
           *
           * @author Shaun McCormick <[email protected]>
           * @license GPLv2
           * @param string $name The name of the variable.
           * @param string $type The type of request. Defaults to GET.
           * @package getreqparam
           *
           * Works with Revolution 2.0.0.
           */
          if (empty($modx) || empty($scriptProperties['name']) || empty($scriptProperties['type'])) return null;
          
          $name = $scriptProperties['name'];
          $type = !empty($scriptProperties['type']) ? $scriptProperties['type'] : 'GET';
          
          switch ($type) {
              case 'SERVER':
                  return isset($_SERVER[$name]) ? $_SERVER[$name] : null;
                  break;
              case 'POST':
                  return isset($_POST[$name]) ? $_POST[$name] : null;
                  break;
              case 'FILES':
                  return isset($_FILES[$name]) ? $_FILES[$name] : null;
                  break;
              case 'COOKIE':
                  return isset($_COOKIE[$name]) ? $_COOKIE[$name] : null;
                  break;
              case 'SESSION':
                  return isset($_SESSION[$name]) ? $_SESSION[$name] : null;
                  break;
              case 'REQUEST':
                  return isset($_REQUEST[$name]) ? $_REQUEST[$name] : null;
                  break;
              case 'GET':
              default:
                  return isset($_GET[$name]) ? $_GET[$name] : null;
                  break;
          }
          return null;
          


          $title = $modx->runSnippet('getReqParam', array('name'=>'pagetitle'));
              $price = $modx->runSnippet('getReqParam', array('name'=>'price'));
              $img = $modx->runSnippet('getReqParam', array('name'=>'img'));



          or just:

          $title = $modx->getOption('pagetitle',$_REQUEST,'');
          $price = $modx->getOption('price',$_REQUEST,'');
          $img = $modx->getOption('img',$_REQUEST,'');



            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 42596
            • 45 Posts
            Neither of these work unfortunately and just return empty variables in the url on the following page.

            Any further Suggestions on how to pass these variables to the next page would be greatly appreciated.

              • 4172
              • 5,888 Posts
              which url does it return now?
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 42596
                • 45 Posts
                http://wheeldeal.co.nz/thank-you!?pagetitle=&price=&carimage=
                  • 42596
                  • 45 Posts
                  ...which again is wierd because, as before with my own snippet, if i just output those variables on the same page it puts out the correct values, which is why I thought it must be a problem with makeUrl in the first place.
                    • 42596
                    • 45 Posts
                    The plot thickens...

                    So now I have tried 3 methods...I went to the original page and made it send through the ID of the resource that has the TV's im trying to use (dont know why i didnt think of that before)

                    So now I have this:

                        $carId = $modx->runSnippet('getReqParam', array('name'=>'id'));
                        $carResource = $modx->getObject('modResource', $carId);
                        $title = $carResource->get('pagetitle');
                        $price = $carResource->getTVValue('price');
                        $img = $carResource->getTVValue('home-img');
                        $url = $modx->makeUrl(17,'',array('pagetitle' => $title, 'price' => $price, 'carimage' => $img));


                    Which, again, when output on the same page works fine and returns exactly what I want but when put into makeUrl I now get the url on the following page: wheeldeal.co.nz/thank-you!?pagetitle=Home&price=&carimage=

                    Literally no idea what is going on...
                      • 3749
                      • 24,544 Posts
                      See if this makes a difference (assuming that it's the web context) - note the 'full' at the end:

                      $url = $modx->makeUrl(17,'web',array('pagetitle' => $title, 'price' => $price, 'carimage' => $img), 'full');


                      It appears that your TVs are either empty, or not being retrieved.
                        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