We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14772
    • 14 Posts
    Hey, I am new to this forum and pretty new to Modx and I was wondering if someone could tell me what the format is for the action in a form. I am putting a mail form on my site and including it in the template via a snippet, but I do not know how to format the action in the form. Usually it is just: action ="whatever.php". In modx is it something like: action = "[~whatever~]"?

    How would I go about doing this??

    Thanks!
      • 10487 MODX Staff
      • 1,535 Posts
      Hi, there are a few options available:

      1. If your form is posting back to the same page as the form is on, then use: [~[*id*]~]
      2. If your form is posting to a different MODx page, then use [~id~] where ’id’ is the ID number of the MODx page.
      3. If you’re posting back to a non-MODx page/file, then use the standard filename, e.g. whatever.php

      Hope that helps,
      Garry
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 14772
        • 14 Posts
        Thanks for your help.

        I will see if I can get that working tomorrow.
          • 14772
          • 14 Posts
          Ok, well for some reason it is not working for me. What I have is: <form action="[~mail~]" method="post">

          In this case the mail is the php snippet that i am referring too. What am I doing wrong here?
            • 14772
            • 14 Posts
            No, my snippet is under Resources then under snippets. So are you saying that I cannot link to it from within the snippet section of resources? So, how do I need to save it so that I can link to it? - Just as a regular php file under the main site with all of my other pages??

            Thanks..
              • 4041
              • 788 Posts
              A snippet is basically a php script which is saved in the resources section, then you add the snippet call to the appropriate spot in your template or document where you want the script output to appear.

              for this example we will use the snippet in a document.

              1.) create a snippet named SampleLogin using the example form code below.
              2.) create a new document or edit an existing one and add the snippet call to the document content area where the form would show like so:
              [!SampleLogin!]
              3.) in the action part of the snippet form code, since this example form posts back to itself, add the document ID (ex: 12)
              <form id=’loginForm’ name=’loginForm’ method=’post’ action=’[~12~]’>

              example form code:
              <?php
              /*  Example form
              
              */
              $output ="";
              
              if(isset($_POST['submit']) && isset($_POST['password'])){
                $output .="<div align='center'>Welcome ".$_POST['webusername'].", you are logged in...</div>";
              
              }else{
                $output .="<form id='loginForm' name='loginForm' method='post' action='[~12~]'>
                  <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>";
              }
              
              return $output;
              <?
              


              This is a very basic example but should help you gain a bit of insight
                xforum
                http://frsbuilders.net (under construction) forum for evolution