Thanks to everyone with replies; I'm looking into your suggestions.
For those that are already using PHPLIB I have the following code to
generate a pull-down menu and have the particular choice <select>ed
assuming that there is a database record with this information. Note
that my code is tab delimited with 2 spaces per tab so if you copy and
paste the code into a text editor everything should look a lot nicer.
1. This is the function(borrow ed from php.net) that queries
table.field and produces an array of values for this field ASSUMING
that it is either of enum or set type.
function mysql_enum_valu es(&$db, $tableName,$fie ldName)
{
$result = $db->query("DESCRIB E $tableName");
//then loop:
while($row = mysql_fetch_arr ay($result))
{
//# row is mysql type, in format "int(11) unsigned zerofill"
//# or "enum('cheese', 'salmon')" etc.
ereg('^([^ (]+)(\((.+)\))?([
](.+))?$',$row['Type'],$fieldTypeSpli t);
//# split type up into array
$ret_fieldName = $row['Field'];
$fieldType = $fieldTypeSplit[1];// eg 'int' for integer.
$fieldFlags = $fieldTypeSplit[5]; // eg 'binary' or 'unsigned
zerofill'.
$fieldLen = $fieldTypeSplit[3]; // eg 11, or 'cheese','salmo n' for
enum.
if (($fieldType==' enum' || $fieldType=='se t') &&
($ret_fieldName ==$fieldName) )
{
$fieldOptions = split("','",sub str($fieldLen,1 ,-1));
return $fieldOptions;
}
}
//if the funciton makes it this far, then it either
//did not find an enum/set field type, or it
//failed to find the the fieldname, so exit FALSE!
return FALSE;
}
2. This is the code that goes into the PHP page that uses PHPLIB's
templates and ooforms. We are using blocks to automate creation of
certain form elements.
include "template.i nc";
$t1 = new Template();
$t1->set_file("MyFi leHandle","pull downs_blocks.ht ml");
$defaults = array (
"message" => "Testing the pull down menu option",
"action" => "inquiry_manage 2.php",
"search_for " => "Search for an inquiry where the person's name is"
);
$t1->set_var($defau lts);
//Pull the 'highest_educat ion' field from the 'Business_Appli cation'
table and show a pull down
$db = new DB_Example();
$result = $db->query("SELEC T `highest_educat ion` , `business_plan` ,
`business_age`
FROM `Business_appli cation`
WHERE `ID` =51");
//if($result)
$row = mysql_fetch_ass oc($result);
foreach ($row as $element => $value) {
//set the blocks
$t1->set_block("MyF ileHandle", "blk_".$element , $element);
//get the choices for Business_applic ation.element to populate the
pull down menu
$choice = mysql_enum_valu es($db, "Business_appli cation",$elemen t);
//output the pull down menu
foreach($choice as $x)
{
if ($x == $value) {
$t1->set_var($eleme nt."_value", "value='".$ x."' selected");
$t1->set_var($eleme nt."_text", $x);
}
else {
$t1->set_var($eleme nt."_value", "value='".$x."' ");
$t1->set_var($eleme nt."_text", $x);
}
$t1->parse($element , "blk_".$element , TRUE);
}
}
$t1->parse("MyOutpu t","MyFileHandl e");
$t1->p("MyOutput" );
3. This is the actual HTML page with the block definitions. Please
note that blocked sections are named 'blk_<element>' and the
corresponding record field is called <element> so that I can parse the
file with the line
$t1->parse($element , "blk_".$element , TRUE);
<table border=0 width="100%">
<tr>
<td>
<SELECT name="highest_e ducation">
<!-- BEGIN blk_highest_edu cation -->
<option {highest_educat ion_value}>{hig hest_education_ text}</option>
<!-- END blk_highest_edu cation -->
</SELECT>
</td>
</tr>
<tr>
<td>
<SELECT name="business_ plan">
<!-- BEGIN blk_business_pl an -->
<option {business_plan_ value}>{busines s_plan_text}</option>
<!-- END blk_business_pl an -->
</SELECT>
</td>
</tr>
<tr><td valign="top">su bmit</td><td><input name='submit'
value='submit' type='submit'></td></tr>
</table>
Henk Verhoeven <ne**@phppeanut sREMOVE-THIS.org> wrote in message news:<cm******* ***@news6.zwoll 1.ov.home.nl>.. .
gonzalo briceno wrote: I have been using phplib for a while and I really like the framework
except for form creation. Maybe it is me but I in my opinion there
isn't a good way to create forms or should I say, everything else is
so well done that the way you create forms seems to be too cumbersome,
in particular making it so that a pull down menu selects a value that
you assign it.
In any case, does anyone know of any php based (or other readily
accepted web language) solution to creating forms?
Any suggestions are welcome
You could use phpPeanuts, but that will require that you embrace OOP
within the environment (architecture?) of the framework. If you do, it
will not only generate forms with dropdown lists, search dialogs,
checkboxes, and navigational links to related objects, but also convert
datatypes, validate user data, report user data entry mistakes, if no
mistakes modify your objects, save them to MySql, retrieve them, cache
them, search for them, page the results, and generate some default reports.
But OTOH, you need basic OOP knowledge (the website does NOT offer an
entry level course OOP). And still the paradigm leap you have to make
may be a bridge too far. Furthermore you may have trouble integrating it
with existing databases and application code. And once you really get
the hang of it, you are likely to percieve your 'old' code as 'legacy'
that urgently needs refactoring or rebuilding. But OK, if you are
learning rapidly (i believe most people here do) the last will probably
happen anyway ;-)
Greetings,
Henk Verhoeven,
www.phpPeanuts.org.
BTW, there are many more frameworks in php, see
http://www.hotscripts.com/PHP/Script...ork/index.html