We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28881
    • 18 Posts
    Well, I guess the title is pretty self explanatory. Is it possible to use a custom PHP form snippet instead of eForm? i.e.


    if (isset($_POST['submit'])){
    $response = validate($_POST);
    }
    
    if (!isset($_POST['submit'])||(!empty($response))){
    
      //display the form and any errors}
    
    elseif(isset($_POST['submit'])&&(empty($response))){
    
        //mail the form
    }


    Or is eForm (or other module) usage mandatory?
      • 10487 MODX Staff
      • 1,535 Posts
      You can process your forms anyway you want - with or without eForm.

      If you don’t want to use eForm: just create your form on a MODx page, place your processing code into a snippet and call the snippet on the page where the form is so that it can process any postbacks from the form. Simple really smiley
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 28881
        • 18 Posts
        Hmm, that’s promising!

        Perhaps you can help me understand what’s going wrong here?

        <?php
        var_dump($_POST);
        
        if (!isset($_POST['submit'])){
          echo"<form action='' method='post'>
          <label for='name'>Name:</label>
          <input type='text' name='name'>
          <textarea name='message'></textarea>
          <input type='submit' name='submit' value='submit'>
          </form>";
        }else{
          echo 'Form recieved';
        }
        ?>


        This code works as a standard PHP page, but not when I try and include it as a snippet. It’s only a test form, but in principle it should display the contents of the $_POST array - at least an empty associative array.
          • 4310
          • 2,310 Posts
          Works for me smiley
          Use the code as the content of a snippet named Whatever
          Call your snippet on the page like this [!Whatever!]
            • 28881
            • 18 Posts
            a-Ha! I was calling the snippet like this:

            [[contact_form]]


            I was calling it with the caching tags... DOH!

            Thanks for your patience everyone - blush...
              • 4310
              • 2,310 Posts
              laugh We’ve all done it.