我正在尝试实现Php表单生成器类,但我得到了
Fatal error: Class 'Form' not found in C:'wamp'www'project'admin'newpost.php on line 18
我正在用php5.4.3运行apache2.4.2,有人知道如何运行它吗?
<?php
session_start();
error_reporting(E_ALL);
include("../PFBC/Form.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled</title>
<link rel="stylesheet" type="text/css" href="style/index.css" />
</head>
<body>
<?php
$form = new Form("layout_grid", 500);
$form->configure(array(
"view" => new View_Grid(array(2, 1, 3))
));
$form->addElement(new Element_Hidden("form", "layout_grid"));
$form->addElement(new Element_Textbox("Title:", "Title"));
$form->addElement(new Element_Textbox("First Name:", "FirstName"));
$form->addElement(new Element_Textbox("Last Name:", "LastName"));
$form->addElement(new Element_Textbox("City:", "City"));
$form->addElement(new Element_State("State:", "State"));
$form->addElement(new Element_Textbox("Zip Code:", "ZipCode"));
$form->addElement(new Element_Button);
$form->render();
?>
</body>
</html
>
我想你对namespaces
、有问题
尝试:
$form = new PFBC'Form("layout_grid", 500);
您有PHP5.3的PFBC版本吗?
$form->addElement(new PFBC'Element'Hidden("form", "elements"));
有一种更短的方法可以实现几乎相同的事情。如果您正在使用PHP >= 5.3
您只需在sessionstart()之后的页面顶部添加"use"关键字因此:
use PFBC'Form;
use PFBC'Element;
在那之后,你只需继续构建你的表单,就像你已经做的那样,你不需要在每行中添加额外的PFBC''。这都在文档中。如果您使用的是5.3
之前的任何php版本,则需要下载替代包。