(04-27-2021, 08:05 AM)hobbyci Wrote: Hello Forum,
I would like to have some hints how to solve this problem.
Making a simple contact form (name, email, message) and send emails to me and a verification email to the user and also store the data in database is not a big deal.
In the most tutorials which you can find in the internet follows more or less the same procedure.
1) Creating DB (contact_form)
2) Creating View (static)
3) Creating Model (depends on, if you wish to store the messages in the database)
4) Creating Controller (static input-vars, static validation rules)
My problem is:
I want to create the view and the controller depending on the database structure.
So, if I decide to extend the database which row e.g. "phone-number" I have to extend the view (new input fiield) and controller files (new validation rule.
I know about CI Form builder.
So I use CI-database method
$this->db->field_data('contact_form');
to get field-name, type, length and primary_key.
With the form builder I can build the form easily.
What about <label> tags?
Here CI-inflector helper can help. function humanize("dashed-string") -> "Dashed String"
How can I set validation rules dynamically? What is the best way to store this? Or to generate those?
I could extend CI-method $this->db->field_data() to get database metafield "comment" and store the validation rules in the comments of the field.
My plan is to write an library/module and later i can just call
$this->load->library('form')
and give the table name as an argument for the constructor.
The library would have properties e.g.
protected $send_verify_email = true/false;
functions like
get_fields($table) -> returns the db-structure
generate_html() -> returns the html form for the view
and so one.
What is a approach to do this?
I would use the EAV model to store the fields and possibly some column with a serialized date (including the validation rules and order view). I would create some query to list the fields and to get the validations rules when the form is submited.