Pagina 1 van 1

PHP Form maak class

Geplaatst: 03 nov 2004, 16:10
door Bas

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;
    } 
} 

?>
Je roept het zo aan:

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");
De output wordt dan zo:

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>
Ik zoek reacties/feature requests!

Geplaatst: 04 dec 2004, 20:00
door Bas
Ik noem dit een "RFC": Request For Comments...