If I have PHP class for example like this:
class Person {
private $dateOfBirth;
private $height;
public function getDateOfBirth() {
return $this->dateOfBirth;
}
public function setDateOfBirth($dateOfBirth) {
$this->dateOfBirth = $dateOfBirth;
}
public function getHeight() {
return $this->height;
}
public function setAge($height) {
$this->height= $height;
}
}
Is there some nice solution how to dynamically generate HTML form according to this class?
<form action="action.php" method="post">
<input type="date" name="DateOfBirth" value="1900-01-01"/>
<input type="number" name="Height" value="180"/>
<input type="submit" class="submit" value="Submit"/>
</form>
The only solution that I came up with is to iterate all properties of class and generate inputs. And if the name of the property contains e.g. 'date' make 'input type="date"'. But I don't really like this solution. Given that property Height is obviously number type, its name doesn't indicate it. And I don't want to rename it. Property names must remain the same.
Thanks for responses