PHP Form maak class

Praat mee over van alles en nog wat!
Forumregels
Dit forum is voor alle zinnige gesprekken buiten phpBB om. Discussies en gesprekken over interessante onderwerpen.

Een nieuw onderwerp moet..:
  • uiteraard voldoen aan de algemene voorwaarden
  • niet passen in de gewone supportfora
  • interessante zijn voor het overgrote deel van onze gebruikers
  • een neutrale of positieve ondertoon hebben
  • anders zijn dan bestaande onderwerpen
Plaats reactie
Gebruikersavatar
Bas
Berichten: 2741
Lid geworden op: 02 dec 2003, 17:38
Locatie: Omgeving Goslar (Duitsland)
Contacteer:

PHP Form maak class

Bericht door Bas » 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;
    } 
} 

?>
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!

Gebruikersavatar
Bas
Berichten: 2741
Lid geworden op: 02 dec 2003, 17:38
Locatie: Omgeving Goslar (Duitsland)
Contacteer:

Bericht door Bas » 04 dec 2004, 20:00

Ik noem dit een "RFC": Request For Comments...

Plaats reactie