

Lets add our validate parameter and make our name, email and comment fields required. In order to achieve this we just need to add the validate parameter to our FormIt call and specify which fields are required in order to submit the form successfully. The next step is to add validation to our form so we can make sure each input field is filled out before submitting the form. Tip: You can also use an input field and use the placeholder as the value for this property in order to allow the user to specify a custom subject, in that case your emailSubject property would look something like this: The first parameter we are passing is the email hook. The (?) lets the snippet know that we are about to send it some parameters or set some properties. So far we have modified our HTML form by adding placeholders to the input fields so FormIt knows where to get the values from, now we have to add our FormIt call which looks something like this: First FormIt Form`įirst we are instantiating the FormIt snippet by calling it uncached ] It is good practice to use the name or ID of your input field as your placeholder in order to keep things relevant but this is not a requirement. Tip: The default FormIt placeholder prefix is fi but this is not mandatory, you can specify your own custom placeholder prefix by adding the placeholderPrefix property to your FormIt call.Īs you can see we are calling our placeholders uncached by using the (!) to make sure we don't receive cached values from previous form entries followed by a (+) which is the placeholder syntax for MODX internal tag system.


All FormIt placeholders must be prefixed with fi so FormIt knows it's a placeholder which pertains to it, so after doing this our forms HTML code should look like this: Name: Email Comment In order to retrieve the values of our form with FormIt we need to add placeholders to our input fields so FormIt knows how to process them. Name: Email Comment Adding Placeholder Tags The first step is to create the HTML for your form, for this example we will create a simple comment form that will have 3 fields that our user will fill out which are: Name, Email and Comment. You can create your own custom Hook and Pre-Hooks and call these in the preHook and hook parameters of FormIt, remember these will be executed based on the order in which they are in your hook or pre-hook call so if one hook fails it will stop and not execute the next one.įor more information on hooks and pre-hooks, see the Hooks on the MODX RTFM page. Hooks can be chained the first hook will execute, and if it succeeds, it will proceed onto the next hook.įormIt also has Pre-Hooks which execute before you load your form a good example of a Pre-Hook is one which sets a default value to your forms input fields for older browsers that don't support the input placeholder parameter. Hooks are basically scripts that run during FormIt processing. Tip: Using FormIt is not necessary, you can also create your own form and PHP code to validate and process your form without the use of FormIt.įormIt works just like any other MODX extra you call the snippet and pass some parameters, FormIt also comes with built in Hooks.
