We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 686
    • 24 Posts
    I created a plugin containing:

    $_GET['id'] = $_POST['id'];


    Didn’t seem to have any affect. Tried to make it fire on:

    OnWebPageInit
    OnLoadWebDocument
    OnParseDocument

    I assume now that the Document Selection (with the id parameter) is done before any plugins get fired. I don’t really want to put this into index.php. But this is a MVC framework so I’m assuming there would be a good place for me to insert this.

    The reason I want to do this is I’m using QuickForm from PEAR, which doesn’t give you control (as far as I know) over the action attribute in the form tag. Its generated. I am pondering making a plugin to do some string manipulation on the form tag after its generated but this will get messy.

    Any suggestions appreciated.
      • 10487 MODX Staff
      • 1,535 Posts
      No plugin event occurs early enough in the parsing process for the ID to be overidden in that way, but I don’t think you need to do that anyway. OnWebPageInit is the earliest event to be called and that happens right after the ID has been resolved by the document parser.

      I’ve only had a quick look at QuickForm but it looks like the action can be passed into the constructor when QuickForm is instantiated. It only self-generates an action if none is provided for it to work with. (A code sample would really help here so I can see how you’re using QuickForm)

      Have a look in QuickForm.php and look for the constructor method and you’ll see what variables can be passed in and the order they need to be passed.
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 686
        • 24 Posts
        Ok, it would have probably been more helpful if I said that I was using QuickForm_Controller. This gives Multi-page functionality.

        A class called HTML_QuickForm_Page inherits HTML_QuickForm. When QuickForm_Page gets instantiated, it calls the parent’s (HTML_QuickForm) constuctor but leaves $action parameter blank. http://pear.php.net/package/HTML_QuickForm_Controller/docs/1.0.7/__filesource/fsource_HTML_QuickForm_Controller__HTML_QuickForm_Controller-1.0.7Page.php.html#a61

          • 686
          • 24 Posts
          The following code I put in index.php is starting to make me question my sanity:

          $_REQUEST['id'] = 68;
          
          if (isset($_POST['pageid'])) 
          {
          	//phpinfo();
          	//echo 'pageid is ' . $_POST['pageid'];
          	//$_REQUEST['id'] = $_POST['pageid'];
          	//$_REQUEST['id'] = 68;
          }
          


          This will lock the site on page id 68. The hidden element on the form named ’pageid’ holds the id that gets overriden in $_REQUEST.

          I comment out the top line, and enable the bottom line in the if-block then it throws me to the front page (id 1).

          If I uncomment the phpinfo(), sure enough I get the phpinfo dump. It also tells me that $_POST[’pageid’] is 68.

          Sometimes I get the feeling that there are some higher forces that want me to phone my customer and say "you know this app I’ve spent a few days on? Well I’m not going to be able to deliver on time, and further more, I have no idea how much longer it will take."

          Any clues anyone (about the code)?
            • 22303 MODX Staff
            • 10,725 Posts
            Some information on what you are trying to accomplish might help here. Why are you editing index.php and forcing the id parameter to 68? You always want the site to go to page 68??? You cannot change the $_REQUEST[’id’] and expect MODx to function properly.
              • 686
              • 24 Posts
              No, I don’t intend to have the site locked on page id 68, that was just a test in an attempt figure out what was going on in my code. Ideally I would just have:

              $_REQUEST[’id’] = $_POST[’pageid’];

              in the if block, which you can see is commented out there. This is what I’m trying to do:

              I’m using the PEAR HTML_QuickForm_Controller, which lets me build forms with Wizard type functionality and validation. The HTML for the form is generated dynamically, including the action attribute in the <form> tag. I have no way of inserting the &id=68 into the action using PHP code. But I can insert hidden <input> tags into the form and in this case, I have one named "pageid" containing the id of the MODx page. Thus I would ideally end up with (if it worked as it should) something like this:

              if (isset($_POST['pageid'])) 
              {
                   $_REQUEST['id'] = $_POST['pageid'];
              }
              


              I would have liked to do this in a plugin, but as garryn said, there are no events that fire early enough to be able to override the page ID in $_REQUEST.

              The thing that is so strange is that it breaks when I alter the $_REQUEST from inside if block. If I alter it before the if block, it works fine. It IS getting into the if block and ’pageid’ IS getting posted. I thought it could be a scope problem, but no... my mind is made up...

              I’m living in the twilight zone.