This topic is locked

Guide 95 – Adding fields to forms that are not (real) database fields

3/20/2025 2:52:15 PM
PHPRunner Tips and Tricks
fhumanes author

img alt
I have used this topic of adding new fields to forms that do not correspond to fields in the database tables many times in examples, but I don't think I have one that is specific to this topic. It is very helpful in resolving some application functionalities and, in addition, it can be simpler to use for the application user.

In the example, we simulate creating an invoice/delivery note, and selecting the Customer gives us the shipping addresses, which are structured as "Master" -> "Detail," and are displayed in a checklist. Additionally, and this is where the example comes in, we want to be able to add a new address in the same form.

Objetive
Explain how we can add new fields to forms, and that these do not have to be fields from the associated table.

DEMO: https://fhumanes.com/sh/

img alt

The "New Address" checkbox and the "memo" address field are not fields in the INVOICE table.

If you are interested in this topic, continue reading the full article at this link .

fhumanes author 3/20/2025

Technical Solution

To add fields, in the table's SELECT statement, we add all the "dummy" fields we need and then define the field type (visual controls) we want them to have.

img alt

At the JavaScript level, we program the "dummy_address" field to not appear until the "dummy_check" field is selected (yellow and blue blocks).

img alt
The pink block is executed when the "Save" button is pressed and what it does is verify that some address has been indicated.

img alt
In the "Before record added" event (yellow block), if a new address has been entered, an INSERT is performed in the "Detail" address table, and the ID of the new record is selected to add it to the corresponding field in the "Master" table.
In the blue block, what is done (and is mandatory) is to destroy the "DUMMY" fields so that PHPRunner does not attempt to insert those fields into the "Master" table.

img alt
When editing the record, we'll see that this is how it looks, so the information is already adjusted to the database structure. If we haven't included the "DYMMY" fields among the displayable fields of the option/page, it's as if they don't exist, and nothing special needs to be done.

I hope you like it.

I'll leave you the example so you can install it on your PCs.