On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • May be that’s so obvious that I will have to blame myself for having asked. :’(
    But I don’t have a clue for this issue at the moment:
    I would like to integrate a <form> element with some input-fields and a submit button in my template (or as a chunk, respectively).
    How can I attach a snippet to the "submit"-event, so that the snippet is executed when the user clicks the "submit"-button?
    I want to implement the functionality as a snippet, since this seems to be the most compatible and organized way to do it.
    • Have the snippet generate the form (use a chunk template and placeholders for the most flexibility, see the eForm snippet). Have the form’s action be empty (or the same page’s ID), that way the snippet can determine whether to display the form (no POST) or process the form’s postback.

      You can just use the eForm snippet with the email option set to 0. It will automatically process your form and do validation checks as well.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
      • put the page id that has the snippet call what will receive the data to the form action attribute, so it would be something like:

        <form name="myform" action="[~69~]" method="post"> 
        <input type="text" name="firstname" />
        <input type="submit" name="submit" value="submit"/>
        </form>


        if the snippet is in document what’s id is 69. Or if you have the snippet on the same document, you don’t have to supply the action attribute, or put action="[~[*id*]~]".

        Then in the snippet do like this to get the input from form:

        if($_POST["submit"]) {
           $fld_firstname = $_POST["firstname"];
           ...
        }


          "He can have a lollipop any time he wants to. That's what it means to be a programmer."
        • Thanks, that helped! wink
          • Thank you guys from ten years in the future.