We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14734
    • 4 Posts
    Hi!
    I am mad about to find the way that forms work in MODx. If I code the same PHP scripts, that I always use normaly, I do not obtain any data. I do not understand how the form works in MODx. . A simple example:
    In MODx, in the page indentify with index.php?id=8, for example I write:

    $data=$HTTP_POST_VARS[’data’];
    If ( !$data){
    <form method="post" action="index.php?Id=8" id="Form">
    <input type="text" name="data" id="data" />
    <input type="submit" value="Submit" />
    </form>
    } else {
    Echo ‘Data:’.$data;
    }
    This never works and I do not understand why undecided. I do not know if exists any way to obtain the data in MODx like alternative of:
    $data=$HTTP_POST_VARS[’data’];
    Also, I have read that exists eForm to manage form information. I test it but, either, I never have access to the data huh
    Please, how I can do this?!
    Thank you very much wink
      • 5274
      • 177 Posts
      There are a number of PHP environment issues that affect how forms react. This page lists a few:

      http://php.net/variables.external

      Also note that $HTTP_POST_VARS is deprecated and is replaced by $_POST.

      http://php.net/manual/en/reserved.variables.post.php
        • 4041
        • 788 Posts
        Here is your code above converted into a snippet to work in modx.

        <?php
        $data=$_POST['data'];
        $output ='';
        if(!$data){
          $output .='<form method="post" action="[~8~]" id="Form">
          <input type="text" name="data" id="data" />
          <input type="submit" value="Submit" />
          </form>';
        }else{
        $output .='Data: '.$data;
        }
         
        return $output;
        ?>
          xforum
          http://frsbuilders.net (under construction) forum for evolution
          • 14734
          • 4 Posts
          First of all thank you for your support!!

          I begin to see the light at the end of the tunnel but it still does not work. I do not know why. huh
          I have created a snippet called: ShowData. Into this snippet I have copied the code that you bring me.
          In a new document I run the snippet simply written [[ShowData]]. And this is the result:

          http://webbo.jormax.net/modx/index.php?id=8

          You can try there the result of submitting the form: NOTHING embarrassed.

          Any idea?

          P.D.: Thank you for your comments about the changes in commands...perhaps I must recycle myself, grin
            • 7231
            • 4,205 Posts
            Whenever working with dynamic data the snippet needs to be called uncached (with [! !] rather than [[ ]]). Try this instead:

            [!ShowData!]
              [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

              Something is happening here, but you don&#39;t know what it is.
              Do you, Mr. Jones? - [bob dylan]
              • 14734
              • 4 Posts
              Really works!!!

              Thank you very very much!!
                • 6852
                • 39 Posts
                Hi,

                im just wondering i have been trying to do something similar. i followed the steps above but still am not getting the output right.

                calling the snippet [!ShowData!] which shows the basic form & displays it on my page, when i complete the form and press submit my form does post the data, does go to the new page but does not post the result on that page?

                i was thinking [+data+] would be what i would need on the new page to place the data in?

                any idea where im wrong?

                thanks very much
                  • 24719
                  • 194 Posts
                  just change your code from ’return $output’ to ’echo $output’
                    • 4041
                    • 788 Posts
                    You have to specifically set placeholders, they are not automatically created. Have a look at the wiki hereabout placeholder setting:
                    http://wiki.modxcms.com/index.php/API:setPlaceholder

                    Also try this snippet:

                    <?php
                    /* this snippet would call a chunk named PostDataTestChunk
                       contents of chunk:
                       
                       <p>Data: [+data+]</p>
                       
                    */
                    $data=$_POST['data'];
                    $output ='';
                    if(!$data){
                      $output .='<form method="post" action="[~8~]" id="Form">
                      <input type="text" name="data" id="data" />
                      <input type="submit" value="Submit" />
                      </form>';
                    }else{
                    // Set placeholders:
                       $DataArray = array(
                                    'data'    => $data
                                    );
                    // Return the chunk
                      $output .= $modx->parseChunk('PostDataTestChunk', $DataArray, '[+', '+]');
                    }
                    
                    unset($data);
                    return $output;
                    ?>
                      xforum
                      http://frsbuilders.net (under construction) forum for evolution
                      • 14734
                      • 4 Posts
                      I am doing a lot of steps in this way. Now I know the enought information to use some scripts made for me into MODx.
                      The next step: edit my own template grin

                      Thank you!