CodeIgniter Forums
Contact form (how to reduce dependencies?) 3.1.11 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: Contact form (how to reduce dependencies?) 3.1.11 (/thread-79134.html)



Contact form (how to reduce dependencies?) 3.1.11 - hobbyci - 04-27-2021

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? Smile


RE: Contact form (how to reduce dependencies?) 3.1.11 - kleber - 04-28-2021

(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? Smile

[Image: WTkS1fN.png]
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.


RE: Contact form (how to reduce dependencies?) 3.1.11 - hobbyci - 04-29-2021

EAV is what I do not want to use. But maybe I should give this a try.

Thanks for your answer.