We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • When generating a URL for forwarding, the query string is being converted from
    ?this=value&that=othervalue
    to
    ?this=value& amp;that=othervalue
    (the editor is modifying the encoded text).

    $return_url = $modx->makeUrl($modx->getOption('resource'), '', array('this' => 'value', 'that' => 'othervalue'), 'full');

    What is the best way to handle this in processing the second key/value set in the resulting $_GET?

    if(!empty($_GET['othervalue'])) {
      $var = $_GET['othervalue'];
    } elseif(!empty($_GET['amp;othervalue'])) {
      $var = $_GET['amp;othervalue'];
    }


    I have seen something like this

    // Fix for & bug in url
    if( $_GET ) foreach( $_GET as $key => $value )
    {
        if( strpos( $key, 'amp;' ) === 0 )
        {
            $new_key = str_replace( 'amp;', '', $key );
            $_GET[ $new_key ] = $value;
            unset( $_GET[ $key ] );
        }
    }


      Studying MODX in the desert - http://sottwell.com
      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
      Join the Slack Community - http://modx.org
    • Hello Susan, I hope I understand your issue right.

      Do you use $return_url for $modx->sendForward? Then you should set $_GET directly before $modx->sendForward and create the url without the parameters. Forwarding is only a MODX internal option and the Browser/Webserver does not see/work those urls.

      If MODX executes a header redirect ($modx->sendRedirect) the Browser/Webserver should do the translation from &​amp; to &. If there is an issue, you should look if the ampersand is somehow double encoded or if you have invisible chars in those ampersands.
      • No, the complete URL is sent to another site, which uses it to return the user back to the MODX site. Any values that are to be displayed to the user must be in the URL.

        https://developer.authorize.net/api/howitworks/dpm/

        The makeURL() function is in the snippet for the "Handle Relay Response" part.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
        • You have two options then (maybe the 'other side' does not parse the url parameter right):
          $modx->setOption('xhtml_urls', false);
          $return_url = $modx->makeUrl(…);
          $modx->setOption('xhtml_urls', true); // or set it to a retrieved value

          or
          $return_url = $modx->makeUrl(…);
          $return_url = str_replace('&​amp;', '&', $return_url);


          If the 'other side' does everything right, you maybe have to url_encode the $return_url (if I remember right: the NVP PayPal API needed that - which has the same workflow as the dpm).

          EDIT: There is a zero width space between & and amp; in the second code block to avoid parsing &​amp; string, so you can't copy the code directly. [ed. note: Jako last edited this post 9 years ago.]