Persisting dynamic form objects

posted in: Forms | 0

In the previous post we looked at the data structure of an example form created with angularjs-form-builder. It includes the meta-data required to specify the form construction.

The next step is to persist or store the entire form, with its content and structure data. We could store it in many ways, but the structure of the json object already matches the application use case of MongoDB. So I looked for a generic ReST interface to MongoDB that will allow us to store whatever is sent from the dynamic form generator in its entirety.

Spire is based on Silex and provides CRUD for any collection and any document format — https://github.com/thinkadoo/spire

If you are lucky your local ?AMPP already has the Mongo driver installed  — http://www.php.net/manual/en/book.mongo.php

To set up the DB from the command line, you need to run MongoDB command line interactive and create a DB (ite) and connect to it:

> use ite
> switched to db ite

To achieve the same in the PHP ReST app you  need to change this in the settings file of spire:

/Projects/spire/spire/settings.php
$MONGODB_CONNECTION_URI = "mongodb://localhost/ite";

Use an AJAX client to test storing some form data in the DB through the ReST endpoint for the “form2” collection:

Screen Shot 2014-04-06 at 4.48.26 PM

Then test if the form data can be retrieved though the ReST end point for “form2”.

Screen Shot 2014-04-06 at 5.20.32 PM

Leave a Reply