

Switch to the "Resources" tab at the left of the Manager. In the body, the H2heading brings in the longtitle field of the resource, and just below it, the resource content field for the main section of the form (more on those in the next section). In the title section above, the title is set with a Resource Content tag for the pagetitle and a System Setting tag for the site name.
#Formz javascript validation for modx code#
Then right-click on the "Templates" section and select "New Template." Put MinimalTemplate in the "Name" field, and the following code (also available at GitHub, here) in the "Template Code (HTML)" text area, then click on the "Save" button.

Once you're in the Manager, click on the "Elements" tab at the left.

Log into the MODX Manager by going to and entering your credentials (JoeTester/TesterPassword). We could use the default template from our MODX install, but it's quite a bit heavier than what we need and fairly slow to load, so we're going to create our own. The point is just to demonstrate what a working acceptance test looks like. There's no JavaScript (though there could be), not much styling, and no validation of the fields other than making sure they're not empty. This is not going to be a very sophisticated form. To make our form work in MODX, we're going to create a template, a resource (document), a chunk, and a snippet with PHP code to both display and process the form.

If this is confusing, it should become clearer as we create the form using these elements. MODX replaces the placeholder tag with the value of the named placeholder. Placeholders are usually set by the code of a snippet. A Resource Content tag looks like this: ], and is replaced by the value of the named field of the resource (e.g., pagetitle, content, description). There are also Resource Content tags and placeholder tags. MODX replaces the snippet tag with the return value of the snippet code, which is always a string. PHP code is held in a snippet and used on a page with a snippet tag: ]. In MODX, no PHP code is allowed in chunks or resource content. In PHP code, MODX can also get the content of the chunk with $modx->getChunk('ChunkName'). When MODX sees a chunk tag, it replaces it with the content of the named chunk. A chunk tag looks like this: ].Ĭhunks contain blocks of HTML. There's a token at the beginning of the tag that tells MODX what kind of tag it is. The template contains MODX tags which pull things into the page. Once it has the resource, MODX gets its designated template from the database. Every resource has a template which is the surrounding HTML for the page. When MODX gets a request, it gets the corresponding resource (document) from the database. We're going to create a page in MODX on our test install, then test it with an acceptance test. If you're familiar with MODX, you can skip this section. It also assumes that you've created the test in the previous article. This article assumes that you've installed and configured Composer, Codeception, PhpUnit, MODX, Java, WebDriver, and ChromeDriver as described in earlier articles.
