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(borrowed 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_values(&$db, $tableName,$fieldName)
{
$result = $db->query("DESCRIBE $tableName");
//then loop:
while($row = mysql_fetch_array($result))
{
//# row is mysql type, in format "int(11) unsigned zerofill"
//# or "enum('cheese','salmon')" etc.
ereg('^([^ (]+)(\((.+)\))?([
](.+))?$',$row['Type'],$fieldTypeSplit);
//# 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','salmon' for
enum.
if (($fieldType=='enum' || $fieldType=='set') &&
($ret_fieldName==$fieldName) )
{
$fieldOptions = split("','",substr($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.inc";
$t1 = new Template();
$t1->set_file("MyFileHandle","pulldowns_blocks.html" );
$defaults = array (
"message" => "Testing the pull down menu option",
"action" => "inquiry_manage2.php",
"search_for" => "Search for an inquiry where the person's name is"
);
$t1->set_var($defaults);
//Pull the 'highest_education' field from the 'Business_Application'
table and show a pull down
$db = new DB_Example();
$result = $db->query("SELECT `highest_education` , `business_plan` ,
`business_age`
FROM `Business_application`
WHERE `ID` =51");
//if($result)
$row = mysql_fetch_assoc($result);
foreach ($row as $element => $value) {
//set the blocks
$t1->set_block("MyFileHandle", "blk_".$element, $element);
//get the choices for Business_application.element to populate the
pull down menu
$choice = mysql_enum_values($db, "Business_application",$element);
//output the pull down menu
foreach($choice as $x)
{
if ($x == $value) {
$t1->set_var($element."_value", "value='".$x."' selected");
$t1->set_var($element."_text", $x);
}
else {
$t1->set_var($element."_value", "value='".$x."'");
$t1->set_var($element."_text", $x);
}
$t1->parse($element, "blk_".$element, TRUE);
}
}
$t1->parse("MyOutput","MyFileHandle");
$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_education">
<!-- BEGIN blk_highest_education -->
<option {highest_education_value}>{highest_education_text} </option>
<!-- END blk_highest_education -->
</SELECT>
</td>
</tr>
<tr>
<td>
<SELECT name="business_plan">
<!-- BEGIN blk_business_plan -->
<option {business_plan_value}>{business_plan_text}</option>
<!-- END blk_business_plan -->
</SELECT>
</td>
</tr>
<tr><td valign="top">submit</td><td><input name='submit'
value='submit' type='submit'></td></tr>
</table>
Henk Verhoeven <news@phppeanutsREMOVE-THIS.org> wrote in message news:<cmrjee$51g$1@news6.zwoll1.ov.home.nl>...[color=blue]
> gonzalo briceno wrote:[color=green]
> > 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[/color]
>
> 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[/color]