We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34244
    • 51 Posts
    I tried to submit this question before, but I can't seem to find it.

    I'm trying to pass a $_POST var from one Revo page to another, but it seems that the $_POST array is getting clobbered (everything else is working fine) or reset. The following snippet returns "this is empty" after I submit a basic form from one Revo page with an input name="submitby" to another with the following snippet in place:
    if (!isset($_POST['submitby'])) {
    $contactemail = "this is empty";
    return $contactemail;
    } else {
    $contactemail = $_POST['submitby'];
    return $contactemail;
    }
    


    Any ideas? Thanks.
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      You can try to dump $_POST to see what's in there too:
      var_dump($_POST);


      Is this how you have it set up?
      1. You are using a single form that has a method of "post" and an action set with the URL to your second page.
      2. You fill in the input with name "submitby" and submit the form.
      3. The second page has just that snippet on it.

      On Twitter you said ".. how to capture $_POST var within a snippet when passing from one page to another", which sounds nothing like your question here, so please clarify what you're doing.
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 34244
        • 51 Posts
        Mark,

        Thanks, yes, sorry again, my Tweet was unclear (damn 140 chars).

        Yes, how I described it above is how I have it set up. Just to be clear:

        1) I have a page that includes the following chunk:

        <form name="contactform" method="POST" action="/email" class="sideform">
           <p>Update your email address on file:<br />
             <span class="bodytexttight">Enter email address:</span> 
             <input name="submitby" type="text" class="frmfld" id="submitby" size="16" />
             <br />
             <input type="submit" class="butn" value="Submit" /></p>
        </form>
        


        2) On the page "email" I have the following chunk that I want updated:

        [[contactPost]]
        <form id="form1" method="POST" name="form1">
        <input class="input" type="text" name="submit_by" value="[[+contactemail]]" size="40" /></td>
        <input class="input" type="submit" name="B1" value="Submit" /> <input class="input" type="reset" name="B2" value="Reset" /></form>
        


        3) Finally, the above chunk contains the following snippet [[contactPost]] (yes, I modified it from the above):

        <?php
        var_dump($_POST);
        //currently returns array(0) { }

        $contactvar = $_POST['submitby'];

        if (!isset($contactvar)) {
        $modx->setPlaceholder('contactemail', 'This is empty!');
        } else {
        $modx->setPlaceholder('contactemail', $contactvar);
        return "";
        }
        ?>

        4) So the upshot is that I'm not getting anything returned from $_POST vars since the dump returns arrray(0) and no value on the form.
          • 38761
          • 12 Posts
          I also notice you use an underscore in the input field:
          name="submit_by"
          But not when u check for the valuel:
          $_POST['submitby']
          Of course a post dump should still show some values.
            • 34244
            • 51 Posts
            Thanks, senkaz, but the form with the input with the underscore--while confusing--is just on the receiving page/form that's not currently sending anything. It's just receiving the value from the first form.
              • 18373 ☆ A M B ☆
              • 3,141 Posts
              This looks like the culprit:

              [[contactPost]]

              You're using a snippet that relies on URL/POST params, so you have to use it uncached, ie:
              [[!contactPost]]


              Same counts for
              <input class="input" type="text" name="submit_by" value="[[+contactemail]]" size="40" /></td>

              the contactemail placeholder can be different per page depending on the URL/POST params, so use it uncached as well:
              <input class="input" type="text" name="submit_by" value="[[!+contactemail]]" size="40" /></td>


              See these Caching Guidelines for more detail on why/what.
                Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                • 34244
                • 51 Posts
                Alas, Mark, I tried that too and I'm getting the same result. Naturally, it is a good idea--just doesn't appear to be the culprit. [ed. note: aesop1 last edited this post 14 years, 8 months ago.]
                  • 18373 ☆ A M B ☆
                  • 3,141 Posts
                  Could be it's redirecting in between going from one page to the other, which would get rid of the post. You can verify that by keeping Firebug or Chrome Dev tools open while submitting the form, it should go to your page in one go and not redirect.

                  To fix, try replacing action="/email" with action="[[~5]]" where 5 is the page you want to post to. It may need /email/ instead of /email, which would result in a 301 redirect to /email/ in which case it'll lose the post vars.

                  Uncaching those snippets isn't a "good idea", it's wrong if you're not doing it.
                    Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                    Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                    • 34244
                    • 51 Posts
                    Mark,

                    Brilliant, it works! It was adding the backslash to "/email/" that did it! And yes, I'll be better about the uncaching as well.

                    [wipes egg off of face]

                    Thanks for your help.