PHP Form maak class
Geplaatst: 03 nov 2004, 16:10
				
				Code: Selecteer alles
<?php
class phpForm {
    var $formname;
    var $fields;
    var $output;
    var $finishedoutput;
    var $working;
    function phpForm()
    {
        $this->output = "";
    } 
    function outputForm($action, $method = "POST")
    {
        $this->finishedoutput = "<FORM action=\"$action\" method=\"$method\"><table>";
        $this->finishedoutput .= $this->output;
        $this->finishedoutput .= "</table><input type=\"submit\" value=\"Submit!\" /></FORM>";
        echo $this->finishedoutput;
    } 
    function addInputText($name, $text)
    {
        $this->working = "<tr><td>";
        $this->working .= $text . ": ";
        $this->working .= "</td><td>";
        $this->working .= "<input type=\"text\" name=\"$name\" />";
        $this->working .= "</td></tr>";
        $this->output .= $this->working;
    } 
    function addInputPass($name, $text)
    {
        $this->working = "<tr><td>";
        $this->working .= $text . ": ";
        $this->working .= "</td><td>";
        $this->working .= "<input type=\"password\" name=\"$name\" />";
        $this->working .= "</td></tr>";
        $this->output .= $this->working;
    } 
    function addTextArea($name, $text)
    {
        $this->working = "<tr><td>";
        $this->working .= $text . ": ";
        $this->working .= "</td><td>";
        $this->working .= "<textarea name=\"$name\"></textarea>";
        $this->working .= "</td></tr>";
        $this->output .= $this->working;
    } 
} 
?>
Code: Selecteer alles
include("./classes/phpform.php");
$form = new phpForm();
$form->addInputText("title", "Vraag titel");
$form->addInputText("naam", "Naam");
$form->addTextArea("vraag", "Uw vraag");
$form->outputForm("?do=add2");
Code: Selecteer alles
<FORM action="?do=add2" method="POST"><table><tr><td>Vraag titel: </td><td><input type="text" name="title" /></td></tr><tr><td>Naam: </td><td><input type="text" name="naam" /></td></tr><tr><td>Uw vraag: </td><td><textarea name="vraag"></textarea></td></tr></table><input type="submit" value="Submit!" /></FORM>