Hi I want to make form dynamically by just passing array of stuffs. I have tried but cannot may be due to my limitation in PHP. Here is what I have so far. Please help me!
class MyForm{
private $formArray;
//pass array to build a form in form of name=>type eg username=>text to a constructor
public function __construct($postArray) {
//make the form POST variables available to the class
$this->formArray = $postArray;
//print_r($this->formArray);
}
//construct a form
public function buildForm($actionFilePath='login.php'){
echo "<form action='$actionFilePath' method='POST' id='loginform'>";
echo "<table border='1', cellpadding='5'> ";
foreach ($this->formArray as $name => $type) {
echo "<tr>
<td><input type='$type' name='$name' id='$name' /></td>
</tr>";
}//end foreach
echo "</table>";
}
}// end form class