I am trying to create a form using an object oriented approach. I am transcribing the code form a php book that I am reading. The approach uses three files and includes or posts to them as needed.
I get the following error when trying to access buildform1.php:
Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE in C:\xampp\htdocs\form2.inc on line 8
My first file is form2.inc
and the code is as follows:
<?php
class Form
{
var $fields=array();
var $processor;
var $submit = "Submit Form";
var Nfields = 0;
function __construct($processor, $submit)
{
$this->processor = $processor;
$this->submit = $submit;
}
fuction displayForm()
{
echo "<form action='{$this->processor}' method='post'>";
echo "<table width='100%'";
for($j=1;$j<=sizeof($this->fields);$j++)
{
echo "<tr><td align=\"right"\">
{$this->fields[$j-1]['label']}:</td>\n";
echo "<td>
<input type='text'
name='{$this->fields[$j-1]['name']}'>
</td></tr>\n";
echo "<tr><td colspan=2 align="center'>
<input type='submit'
value='{$this->submit}'></td></tr>\n";
echo "</table>";
}
function addField($name,$label)
{
$this->fields[$this->Nfields]['name'] = $name;
$this->fields[$this->Nfields]['label'] = $label;
$this->Nfields = $this->Nfields + 1;
}
}
?>
My second file is buildform1.php
and the following is the code contained:
<?php
require_once("form2.inc");
echo "<html><head><title>Phone Form</title></head><body>";
$phone_form = new Form("process.php", "Submit Phone");
$phone_form->addField("first_name", "First Name");
$phone_form->addField("last_name","Last NAme");
$phone_form->addField("phone","Phone");
echo "<h3>PLease fill out the follwing form:</h3>";
$phone_form->displayForm();
echo "</body></html>";
?>
The third file process.php, I assume is empty and is to take the information from the form and store it. The book doesn't touch upon this third file more then to refernce it and include it in the code.
Any help is appreciated!