https://github.com/fefe33/php-functions
https://github.com/fefe33/php-functions
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/fefe33/php-functions
- Owner: fefe33
- Created: 2024-09-16T17:08:03.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-09-27T06:17:51.000Z (8 months ago)
- Last Synced: 2025-02-06T22:42:10.950Z (4 months ago)
- Language: PHP
- Size: 24.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
PHP functions for writing HTML
Table class
call the constructor:
$mytable = new Table([<titleA>, <titleB>], [[<value_A1>,< value_A2>],[<value_B1>,<value_B2>],...);
apply styles
$mytable->style(<element_or_set>,<inline_css>);
valid elements and sets of elements include:
- table --> which applies to the html table wrapper
- head --> which applies to the thead wrapper
- body --> which applies to the tbody wrapper
- rows --> which applies to all of the rows (tr) contained in the generated table
- cells --> which applies to all of the individual cells contained
return the HTML
$mytable->write();
Form class
call the constructor:
$myform = new Form(<formID>, <action>, <method>);
add inputs
methods:
for text based inputs:
$myform->text_input($name, $type, $attributes)
where valid types include:
['text', 'search', 'email', 'password', 'tel', 'url']
for fieldsets:
$myform->fieldset($name, $label, $selection)
where
$selection
is in the following format:array('label'=>'value', 'label'=>'value', ...]
for range sliders:
$myform->range_input($name,$label,$min,$max,$step);
for numeric inputs:
$myform->numeric_input($name,$label,$min,$max,$step)
for datetime inputs:
$myform->datetime_input($name, $label, $type)
where valid types include['time', 'date', 'datetime-local', 'month']
for submit buttons:
$myform->submit_input($innerText, $is_button, $attr)
, where $innertext is the text either as the value attribute when its not a button or the inner text when it is.
for numeric inputs:
$myform->numeric_input($name,$label,$min,$max,$step)
return the HTML:
$myform->write($break);
where $break is a boolean value determining whether or not to add line breaks between elements
id structure in returned HTML
IDs are all based on the original formID provided in the constructor. each input within the form has an id whose syntax is as such:
$formID-<int>
where the integer is the index of the input relative all the others in the form (whose order is determined by the order in which one calls the methods). radios contained in fieldsets have ids in a different syntax:formID-<int>-Name-<int>-
. the first int is the index of the fieldset relative to the form, the second is the index of the radio-element relative to the fieldset.
see file example.php for more detailed examples of how to use the different methods.