We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4385
    • 372 Posts
    I have a login form that I want to submit the username and look them up via a web service then depending on what I get back submit their username and password to a different POST action, to log them into the correct site.

    Make sense? No?

    Form on my MODX site has username and password.

    I send the username to a web service, and it return to me a 1,2,3 or 4.

    If I get a 2, I post username and password to url 2.

    I wanted to do this with MODX, but maybe it would be better with javascript?
      DropboxUploader -- Upload files to a Dropbox account.
      DIG -- Dynamic Image Generator
      gus -- Google URL Shortener
      makeQR -- Uses google chart api to make QR codes.
      MODxTweeter -- Update your twitter status on publish.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You could use a posthook, and have the hook's code use cURL to submit a post to the appropriate URL.

      http://hayageek.com/php-curl-post-get/
        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
        • 4385
        • 372 Posts
        I tried using cURL, but all that did was post the data. I want it go and login in to the other sites.
          DropboxUploader -- Upload files to a Dropbox account.
          DIG -- Dynamic Image Generator
          gus -- Google URL Shortener
          makeQR -- Uses google chart api to make QR codes.
          MODxTweeter -- Update your twitter status on publish.
          • 3749
          • 24,544 Posts
          You could send them on with $modx->sendRidirect($url) and the credentials in the URL query string, but that's probably unacceptable from a security standpoint.

          If the other pages are using the Login snippet, I think you can add service="login" to the URL.

          That said, it might be easier to do it with JavaScript or cURL where you can set the $_POST variables yourself.

          If the other pages are under the same MODX install, you could also just log the user in to them yourself in the hook, then do the forward. [ed. note: BobRay last edited this post 11 years, 9 months ago.]
            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
            • 13428 ☆ A M B ☆
            • 1,031 Posts
            @Bob: You can't send the $_POST data as POST variables with sendRedirect. You can only send them as GET that way.

            @bwente: It is possible to send that POST variables in the background with cURL. But since this is a communication between two web servers, you can't establish a login session between the user and the second server that way and redirect the user to that server after.

            A redirect to the second server with user/password as GET variables should not be done, because they are visible for the user then and could be used for a direct access. Normally this redirect is done with an auth token.
              • 4385
              • 372 Posts
              Thank you all for info. But I love using MODX so much. (When all you have is a hammer, everything looks like a nail.)

              I think this is one task better handled with JS.

              Using JS I can have the button action submit to the service, get my response, then switch the url of the post action.
                DropboxUploader -- Upload files to a Dropbox account.
                DIG -- Dynamic Image Generator
                gus -- Google URL Shortener
                makeQR -- Uses google chart api to make QR codes.
                MODxTweeter -- Update your twitter status on publish.
                • 3749
                • 24,544 Posts
                @Jako: You're right of course. Post corrected. smiley
                  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