This is an example of a simple form. Try out all of the form actions and see how it works, then scroll down to see the source code and template used.
This code is a basic example of what dbForm is capable of. It is a simple example but has enough to show basically all of the field types available. This example could have been simpler but it would not have shown all of the field options.
There is really only six parts to the source code
- Includes and setup
This section includes the necessary class files and creates the ADODB database connection. - Create the dbForm instance
This creates the instance of the dbForm class. The only parameter which is manditory is the first one, and there are others not used in this example (See manual for more details) - Pre-Processing Setup
This section is where you make any alterations to the default table before processing. Any methods that effect the design of the form are called here, including adding and removing fields and buttons, changing field types etc. - Processing Form
This processes any data passed from the form and performs any actions. - Pre-Display Setup
During this part we retrieve any select list data and set the template to be used.
Note: Although searchid is a selection list we do not have to retrieve the data for this list as it is done automatically for us. - Display Form This displays the form using the given template. At this point we are finished although it is good to cleanup database connections etc.
View source code for demo1.php
While it might not appear it at first glance this is a fairly simple template. The main thing of note is the use of the {:action="..."}...{:end action} tags. These tags are used to decide when parts of the form, in this case field and buttons, will be shown.
The {:action="..."} tag contains a comma seperated list of actions. Note that 'null' is a special action that exists when the form is first loaded.
View source code for demo1.tpl
The files that have been used in this demonstration can be downloaded so you can try them out for yourself.