All pastes #792480 Raw Edit

Stuff

public text v1 · immutable
·published 2007-11-21 13:05 UTC
rendered paste body
<?php

/**
 * @author Ionut Cosmin Gherghe
 * @mail cosminlinux@gmail.com
 * @copyright 2007
 */

class Form {
	var $fields = array();
	var $procesor;
	var $submit = "Submit Form";
	var $Nfields = 0;

function __construct($procesor,$submit) {
	$this->procesor = $procesor;
	$this->submit = $submit;
}

function displayForm() {
	echo "<form action = '{$this->procesor}' method = 'post'";
	echo "<table>";
	for ($i=1;$i<=sizeof($this->fields);++$i) {
		echo "<tr><td>{$this->fields[$i-1]['label']	}:</td>";
		echo "<td><input type = 'text' name = '{$this->fields[$i-1]['name']}'</td></tr>";
	}

echo "<tr><td><input type ='submit' value = '{$this->submit}'></td></tr>";
echo "</form></table>";
}

function addField($name,$label){
	$this->fields[$this->Nfields]['name'] = $name;
	$this->fields[$this->Nfields]['label'] = $label;
	$this->Nfields = $this->Nfields + 1;
	}
}

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 following form:</h3>";
$phone_form->displayForm();
echo "</body></html>";
?>