« Common Header & Footer Includes | Main | Cycling in the Trossachs »
March 31, 2009
Building Forms With interface_functions.php & .skini Files
There are a set of functions for rapidly building web forms to work with the SQL functions. These are found in the common_php/interface_functions.php
.
The build_form($form_name, $entity)
Function
This is the guts of the interface system and allows you to build web forms quickly and consistently and avoids problems caused by typos in hand coded mark-up.
The function takes a filehandle for a skins/blah.skini
file, and a hash to populate the form with values if required. I have avoided doing this however, in favour of using AJAX for populating forms when required instead.
build_form('panel_form');
This will look for and read a file in the skins
directory called panel_form.skini
and build the form based upon the settings found therein.
The .skini
Configuration File Format
These files are in Windows .ini
format:
; Each form element should have its own section block. ; ; Sections must be uniquely named as id attributes are assigned ; based upon them ; ; A 1 means that the section is displayed as a block and 0 ; means it is displayed inline. Inline display is trixy and ; requires extra CSS jiggery pokery more often than not. [sections] current_panels = 1 name_section = 1 description_section = 1 location_section = 1 ip_address_section = 1 ; For each item under the 'sections' heading there needs to be a ; separate configuration block. ; ; The block description should include a label entry (usually label_italic) ; and then the form element included in that section. [current_panels] label_italic = "Edit Existing Panel" current_panel_id = select_noadd panel_id = hidden ; If you want to add extra attributes to a form element's tag then ; you can by defining a section headed as below. This is useful for ; adding classes, style attributes or JS event handlers: [current_panel_id] class = four_c onchange = "get_panel_details()" [name_section] label_italic = "Panel Name" panel_name = text [panel_name] class = four_c [description_section] label_italic = "Panel Description" panel_description = textarea [panel_description] class = four_c [location_section] label_italic = "Panel Location" panel_location_id = select_noadd [panel_location_id] class = four_c [ip_address_section] label_italic = "IP Address" ip_address = text [ip_address] class = four_c
The build_repeating_form($form_name, $entity, $the_count)
Function
If you need to build more than one instance of the same form in a single document then you should use this function. This adds the value passed into the third parameter onto the end of all id attributes in the form, separated by an underscore. This is so that we don't duplicate ids.
The get_hour_options()
& get_minute_options()
Function
To be used along with common_php/option_switcher.php
for when you need to choose hours and minutes from <select/>
elements.
Tags: Lightweight PHP Web Application Framework
Posted by pj at March 31, 2009 12:51 PM