This topic is locked

Add custom fields Runtime

3/20/2020 7:47:04 AM
PHPRunner General questions
A
aalekizoglou author

I am trying to implement a method to add custom fields to list/edit/add/search/print during runtime, something we have done with our DELPHI development for off-the-self products.

What I seek is to build a PHP product with a common DB schema. In case a customer wants to add specific fields on a table, have some extra code to add those during the runtime to appropriate forms. That way we can maintain a single codebase, and have customization for each customer.
Anyone have any idea how to implement:

  1. Add fields to list/add/edit/print/search pages during runtime
    I am going to have a single table with such a schema:

  • TABLE NAME
  • CUSTOM FIELD NAME
  • CUSTOM FIELD LABEL
  • CUSTOM FIELD TYPE
  • CUSTOM FIELD JS VALIDATION


For every table I want to add custom fields, I am going to have rows in the above table. Code in:

  • Before SQL Query will have to include custom fields in the select statement,
  • Before Display will have to add fields to relevant forms
  • Before Record Added / Updated will have to save field value to DB custom fields


Any thoughts for adding fields to forms during runtime?

mbintex 3/20/2020

Thought of that too, since for Saas this would add a maximum flexibility.
What I have done so far are two things:

  1. Add some more textfields as needed, allow the user to name these fields via a settings table, have these labels as Session-Variables and echo these instead of "field1", "field2" etc. You could even hide field3 or so if the Session variable for the label is empty.
  2. Allow the user to hide fields via settings table for that purpose: Took that from here: https://xlinesoft.com/blog/2015/12/04/storing-field-labels-and-visibility-rules-in-the-database/
    So you can add and hide fields. Of course adding fields on the fly including field types and changing the table itself would be a big step forward for PHPRunner and Saas.

A
aalekizoglou author 3/20/2020



Thought of that too, since for Saas this would add a maximum flexibility.
What I have done so far are two things:

  1. Add some more textfields as needed, allow the user to name these fields via a settings table, have these labels as Session-Variables and echo these instead of "field1", "field2" etc. You could even hide field3 or so if the Session variable for the label is empty.
  2. Allow the user to hide fields via settings table for that purpose: Took that from here: https://xlinesoft.co...n-the-database/
    So you can add and hide fields. Of course adding fields on the fly including field types and changing the table itself would be a big step forward for PHPRunner and Saas.


Yes,
this is what we have implement with our SaaS desktop products. In fact we allow scripting language (Pascal/Basic) for every form so that after the form initialization we run the per form script to add custom fields with validations, etc. Single code base, multiple customized installations based on customers' specific needs.

Sergey Kornilov admin 3/20/2020

My advice would be to add a bunch (20?) fields to that table in advance, hide all of them initially and control visibility, labels and everything else through your additional settings table.