We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32365
    • 42 Posts
    I’m just curious if there’s any special code I need to use, or if it would just look like this;

    action="[[phpSnippet]]"

    or if I just need to upload the php to a folder and link it like normal.
      • 3749
      • 24,544 Posts
      Not quite. smiley

      You need to either:

      1) Put the snippet on a separate page and make the action a link to that page action=[~##~]" (where ## is the id of the page with the snippet).

      2) Put the snippet on the same page and have the form post to itself action="[~[*id*]~]". In that case the snippet needs to make sure it’s a repost before acting.
        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
        • 32365
        • 42 Posts
        1. I’m guessing the page it’s posted on needs to have a completely blank template applied to it.

        2. What do you mean by "making it a repost"? I didn’t see any option for it in the snippets options.

        Sorry if I’m bugging you. I got a user page-creation form working using a form outside of the CMS(by editing the database), but now I need to test my user session recognition feature while logged into the CMS.
          • 4041
          • 788 Posts
          Here is a simple example of posting a form back to the same page:

          <?php
          /*  Example login form
              * form posts back to the same page
              
              usage: uncached   [!ThisSnippetName!]
          */
          $output ='';
          
          // get the current document id to use in the action of the form
          $this_docid = $modx->documentIdentifier;
          
          
          // if the form has been posted
          if(isset($_POST['submit']) && isset($_POST['password'])){
          
            // do whatever actions here if the form has been posted
            $output .='<div align="center">Welcome '.$_POST["webusername"].', you are logged in...</div>';
          
          }else{
          // otherwise show the form
            $output .='<form id="loginForm" name="loginForm" method="post" action="[~'.$this_docid.'~]">
              <table width="300" border="0" align="center" cellpadding="2" cellspacing="0">
                <tr>
                  <td width="112"><b>Login</b></td>
                  <td width="188"><input name="webusername" type="text" class="textfield" id="webusername" /></td>
                </tr>
                <tr>
                  <td><b>Password</b></td>
                  <td><input name="password" type="password" class="textfield" id="password" /></td>
                </tr>
                <tr>
                  <td> </td>
                  <td><input type="submit" name="submit" value="Login" /></td>
                </tr>
              </table>
              </form>';
              
          }
          
          return $output;
          ?>
            xforum
            http://frsbuilders.net (under construction) forum for evolution
            • 32365
            • 42 Posts
            Quote from: Breezer at Nov 15, 2009, 07:57 AM

            Here is a simple example of posting a form back to the same page:

            <?php
            /*  Example login form
                * form posts back to the same page
                
                usage: uncached   [!ThisSnippetName!]
            */
            $output ='';
            
            // get the current document id to use in the action of the form
            $this_docid = $modx->documentIdentifier;
            
            
            // if the form has been posted
            if(isset($_POST['submit']) && isset($_POST['password'])){
            
              // do whatever actions here if the form has been posted
              $output .='<div align="center">Welcome '.$_POST["webusername"].', you are logged in...</div>';
            
            }else{
            // otherwise show the form
              $output .='<form id="loginForm" name="loginForm" method="post" action="[~'.$this_docid.'~]">
                <table width="300" border="0" align="center" cellpadding="2" cellspacing="0">
                  <tr>
                    <td width="112"><b>Login</b></td>
                    <td width="188"><input name="webusername" type="text" class="textfield" id="webusername" /></td>
                  </tr>
                  <tr>
                    <td><b>Password</b></td>
                    <td><input name="password" type="password" class="textfield" id="password" /></td>
                  </tr>
                  <tr>
                    <td> </td>
                    <td><input type="submit" name="submit" value="Login" /></td>
                  </tr>
                </table>
                </form>';
                
            }
            
            return $output;
            ?>

            So I input my form at the bottom, put my current php code inside the output below this line ;

            // do whatever actions here if the form has been posted

            and insert the snippet onto the page?
              • 32365
              • 42 Posts
              Alright I got the other page working. My script worked too laugh . Now to move on to the next phase.