I am building a PHP application with CakePHP 2.
I need to have page where a form is displayed.
The form has to be dynamically generated based on configurations stored in a database.
For example :
Database content :
{
{name:"Username",type:"text",label:"Username",validation:("required","minlength:6")},
{name:"Password",type:"password",label:"Password",validation:("required","minlength:6")},
{name:"Submit",type:"submit",value:"submit"}
}
I want some config like this (Format Negotiable) to be stored in a database and based on that a html form would be generated at run-time. If the config is changed at run time the form would also change.
I understand that cakePHP has a form generation component.
So my question is How do I actually get from a config stored in a database to cakePHP form generator and then to the page ?
I was considering the eval() function, but I read that it was not really safe, and I am trying to avoid it if possible.
PS:
I will be using mongodb for storing the data obtained from the form.
The way that the form configuration is stored in the database is flexible,I am thinking of storing it as a string but that is negotiable.
I am also open to storing the configuration for the form in any database be it a RDBMS or a NoSQL database.
Parse the config from the database (use a data serialization function like
serialize(),json_encode(), or an xml serializer.. whatever is convenient) and build the form using http://book.cakephp.org/2.0/en/core-libraries/helpers/form.htmlAnd so on..