I plan on making this a module at some point, but want to go ahead and release this as a helper class with a sample snippet to see if anyone finds it useful before deciding on how it should evolve.
I used this and another class I released recently,
MakeTable, to replace three different extranet sites that included different views into the same database tables. The sites were originally built with a commercial RAD development tool called
CodeCharge Studio, but I convinced the client I could do it better with MODx. I came up with MakeTable and MakeForm because I had some 45 different tables and forms to reproduce (and fix), and the data structures I had to work with would make any serious database administrator spontaneously combust at first sight. The project was a huge success, and changes to the forms rarely take more than 5 minutes of my time, and data structures changes can be handled in minutes rather than hours.
What is MakeForm?
MakeForm helps you quickly build forms for adding/editing records in a database. It does this using three major components:
- Form arrays. First, every form element is represented by an array. This array defines all of the placeholder values that can be used inside the next key component.
- Form element templates. Each element type uses a chunk as a template, so you can customize the way each element type is generated.
- Form processing. You can easily process POST form data against a specified database table using MakeForm and some new DBAPI features new to MODx 0.9.1. You can see these new features used in the source of the makeform.class.inc.php file.
How do I check it out?
I’ve provided a sample snippet (this is meant to be viewed in the MODx default sample template and might need some additional CSS to be viewed properly in other templates/styles as a result), a set of form element template chunks, and the class in the attached zip. This needs to be extracted into the /assets/modules/makeform/ directory (like I said, I plan to make it a module eventually). Once that is done, you’ll need to take the following steps to view the sample:
- First, copy the contents of each one of the MakeForm-*.chunk.html files to a chunk, naming it after the filename, but without including the .chunk.html suffix. [NOTE: I add these suffixes to identity the type of MODx object it is and the type of content so I can edit it properly in an IDE]
- Create another chunk named sampleFormTpl and copy the contents of the sampleFormTpl.chunk.html into it
- Next create a new snippet called MakeForm-Sample with the following content:
return include($modx->config['base_path'] . "assets/modules/makeform/MakeForm-Sample.snippet.php");
- Finally, create a new non-cacheable document in MODx and copy the content from the MakeForm-Sample.document.html file into your new document’s content editor (use HTML source mode if you use an RTE, for best results
).
When you visit the page you created in the last step, assuming the database user you are using to connect to MODx has permissions to create a new database table in the MODx database, the table will be created if it does not exist, and it should display a form (or a bunch of errors in a red background

).
Let me know if you find this useful or full of errors.
[UPDATED: Corrected MakeForm-InputSubmit.chunk.html and MakeForm-InputButton.chunk.html with name=[+name+] as reported by sottwell]