We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25357
    • 92 Posts
    Or any input, for that matter, $_REQUEST, $_GET?

    Revo 2.04, Linux, working along on a snippet that uses a posted form, it was working fine, then out of nowhere . . . poof. Nothing from $_POST, $_GET, or $_REQUEST. I thought it was a server issue, wrote up a small standalone script, it accepts post just fine. When I post to my snippet in modx, here’s the clif notes from Live HTTPHeaders:

    POST /order-test HTTP/1.1
    HTTP/1.1 302 Moved Temporarily

    I’m guessing something is doing a redirect somewhere, but can’t figure out where. It was working fine. I am using friendly URL’s and all seems well, nothing has changed in the setup.

    I’m in dire straits here if anyone knows where I can look.
      • 3749
      • 24,544 Posts
      I would start by turning off FURLs and renaming .htaccess. If that cures it, you know it’s a FURL problem -- most likely with your rewrite base, rewrite rules, or a missing <base href...> statement in your template.
        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
        • 25357
        • 92 Posts
        Thank you! Base href is fine, tried the new .htaccess, no go. Since the original question I’ve done this, this works. It’s aliased to /post-test too.

        [[!postTest]]

        <?php
        if ($_POST[’test’]) { return $_POST[’test’] . " posted"; }
        else {
        return "
        <form method=\"post\" action=\"post-test.php\">
        <input type=\"submit\" name=\"test\" value=\"Test Me\">
        </form>
        ";
        }
        ?>

        Prints out "Test Me posted" as expected. So it’s obviously something in my snippet or page. The only thing I did was add a different snippet in another part of the page, don’t know why that would have made a difference. Off to rip it up, it’s due . . . last week. :-(

          • 3749
          • 24,544 Posts
          Conflicting placeholders? Or, more likely:

          an = where there should be an ==.

          Feel free to post the code of the second snippet (or both of them). Sometimes another set of eyes helps.
            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
            • 25357
            • 92 Posts
            The first is rather large, but it’s not that, it was (and still is) working, as you’ll see. I did try changing the variable names, and just test for isset first

            if (isset($_POST[’whatever’])) {
            }

            The second one is simple:

            <?php
            //[[!snippetname? &parent=`[[*id]]`]]
            if (! isset($parent)) { return ’’; }
            $content = null;
            $table = $modx->getFullTableName(’site_content’);
            $query = "select pagetitle,content from $table where published=1 and parent=$parent limit 1";
            $res = $modx->db->query($query);
            if ($row = $modx->db->getRow($res)) {
            $title = $row[’pagetitle’];
            $content = $row[’content’];
            }
            if ($content) {
            $content = "
            <div class=\"some-class\">
            <h5>$title</h5>
            $content
            <div class=\"box-bottom\"></div>
            </div>
            ";
            }
            return $content;
            ?>

            It gets curiouser and curiouser. I’ve managed to duplicate it, just don’t know why or how it’s doing it.

            I create a document, in that document’s template in one area is the placeholder for the snippet that accepts posts.

            I create a second document that is a child of this document. In another part of the parent document is the snippet above (long story, think like (get a list of the titles for all children of this document.") So what happens is it’s reading this child and outputting some stuff.

            As soon as I add the snippet for the second one to the template, poof, no post data and it 302’s. What’s REALLY weird - switching back to a different template, removing the snippet calls, whatever, nothing seems to make it work. It’s as if the sickness "sticks" to the database entry or something which is impossible.


            CORRECTION: It’s not the adding of the snippet at all. I just re-did the above scenario again, everything was working fine. Posting fine but of course the snippet above doesn’t find any children.

            As soon as I ad a child resource - poof. Goners. Remove the resource? Still broken.

            BTW I’m clearing cache with every update too. Maddening. Boss’s face is red. :-(
              • 7327
              • 195 Posts
              Hey,

              $query = "select pagetitle,content from $table where published=1 and  parent=$parent limit 1";


              $query = "select pagetitle,content from ".$table." where published=1 and parent=".$parent." limit 1";

              Does that help?

              You might want to print out the $query to the screen first and see if that works with the db.
                • 3749
                • 24,544 Posts
                First of all, you never want to use the name of a resource field as a variable name ($content).

                So I suspect that $content = null is your culprit. The standard return variable is $output and you can be sure it won’t mess with anything.

                Second, the whole dbQuery thing is deprecated. You want to be using xPDO. Are you looking for the children of the ID sent in $parent (that’s what it looks like your code does)?

                If so, try this:

                <?php
                //[[!snippetname? &parent=`[[*id]]`]]
                if (! isset($parent)) { return ''; }
                
                $c = array (
                           'id'=>$parent,
                          'published'=>'1',
                          'deleted'=>'0';
                );
                
                $c->limit(1);
                
                $resources = $modx->getCollection('modResource',$c);
                
                if (empty($resources)) {
                   return 'No Resources';
                }
                $output = null;
                
                foreach($resources as $resource) {
                
                     $output .= "
                     <div class=\"some-class\">
                     <h5>$resource->get('pagetitle')</h5>
                     $resource->getContent();
                     <div class=\"box-bottom\"></div>
                    </div>
                    ";
                }
                return $output;
                
                

                  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
                  • 25357
                  • 92 Posts
                  $query = "select pagetitle,content from ".$table." where published=1 and parent=".$parent." limit 1";

                  Thanks, however the queries run fine - double quotes interpolate. Even it if didn’t it would just fail without output, wouldn’t kill my $_POST.

                  you never want to use the name of a resource field as a variable name ($content).

                  Thanks Bob but this snippet is not the problem. I did rename all my vars though thinking it might be an issue, and since this post, the whole child idea has been eliminated. I’ve moved it to a TV. It’s helpful to remember I deleted the snippet call at the first sign of trouble and it had no effect . . . $_POST vars gone with a 302 Temporarily Moved header.

                  Which worked. for a while. Then out of nowhere . . . .post variables gone again. If I keep clearing the site cache sometimes it comes back, sometimes it doesn’t.

                  Scenario: I’m updating the scriptlet, modifying the styling, etc., refresh, posts, refresh, posts, then again . . . no post data and goes back to first state. I swap out templates, clear cache, starts working again without any code changes. Weirdest thing I’ve ever seen.
                  $query = "select pagetitle,content from ".$table." where published=1 and parent=".$parent." limit 1";
                    • 7327
                    • 195 Posts
                    When you hit the refresh button, you’re getting that resend POST data message box right?
                      • 25357
                      • 92 Posts
                      Thanks diatomin, but of course not - that’s the whole problem. It posts, then redirects which is a get, so there’s nothing to re-post at that point.

                      After two days I figured it out, including taking the entire thing out of modX as a standalone script - and still having the same problem. Then moving it to another server in desperation only to realize - doh - this server also has modX installed and has the same condition! LOL . . .

                      But modX is not at fault, at least, not directly. In my standalone script I modified the URL:

                      /some-directory/

                      to

                      /some-directory/index.php

                      And poof, all was well. The problem I was having is the issue was not repeatable - but once I did this, it was. Change the post URL to /some-directory/, it broke. Add index.php, it worked.

                      So back to modX, as we need this in the system. What was it? This should be fine, and IS fine on all my other modX installations (I control about 8 ATM:)

                      RewriteCond %{REQUEST_FILENAME} !-f
                      RewriteCond %{REQUEST_FILENAME} !-d
                      RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

                      I made one single change, telling mod_rewrite to look from the domain root . . .

                      RewriteCond %{REQUEST_FILENAME} !-f
                      RewriteCond %{REQUEST_FILENAME} !-d
                      RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]

                      (note the slash.) And all is well again. You would think RewriteBase / would solve this. For whatever reason, it didn’t.

                      What a freaking week. :-P