This is what I have been working on lately. Just off the bat, I realise there is a pear extension like this already, although I want to create my own. Layout may appear a little off.
Things I haven't completed yet.
- rules system
- data validation prior to form creation (creation data itself [needed ?])
- some conditionals (still works though)
Controlling the object.
Create Object:
new createforms();
Start form:
startForm('name', 'method', 'action', 'css_class', enabled?);
Add Element Type: [view_array optional with all types]
addType('element_type', 'element_name', 'element_title', data_array/data_string, view_array);
Build and Display form:
execForm();
Element Types (example of use below):
text, password
-data_string [optional]
checkbox/radio
textarea
submit, reset, file, button [picture not functional at this point]
dropdown (select menu)
Example:
<html>
<head>
<link rel="stylesheet" type="text/css" href="css.forms.css" />
</head>
<body>
<?php
$radio_1 = array(
"title" => "test1",
"value" => "test_1"
);
$radio_2 = array(
"title" => "test2",
"value" => "test_2"
);
$radio_3 = array(
"title" => "test3",
"value" => "test_3"
);
$radio_4 = array(
"title" => "test4",
"value" => "test_4"
);
$radio_5 = array(
"title" => "test5",
"value" => "test_5"
);
$data_array = array($radio_1, $radio_2, $radio_3, $radio_4, $radio_5);
$login = new createforms();
$login->startForm('test', 'post', ' ', 'Right_Menu', true);
$login->addType('text', 'username', 'username');
$login->addType('password', 'blah', 'password');
$login->addType('checkbox', 'radio_1', 'User Type', $data_array);
$login->addType('radio', 'radio_1', 'User Type', $data_array);
$login->addType('textarea', 'testbox', 'blkaj');
$login->addType('submit', 'submit', 'buttontest');
$login->addType('dropdown', 'tester', 'tester', array("option1" => "Eat Me", "option2" => "Eat Them"));
$login->execForm();
?>
</body>
</html>
Just wondering on peoples views on this, what should change, how/if I need to handle things differently, suggestions are always welcome.
Thanks in advance.