PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Outdated profile   formbuilder   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Simple example well commented
Class: formbuilder
Class for easy composing of complex forms
Author: By
Last change: Minor bug fixes and improvement of combo functions.
Date: 21 years ago
Size: 4,765 bytes
 

Contents

Class file image Download
<html>
<head>
    <style type=text/css>
        .forminput { font-family: Verdana,Tahoma,Arial; font-size: 11px; background: #ffffff; color: #000000; border: 1 solid #AAAAAA; }
        .formtextarea { font-family: Arial Narrow, Arial, Verdana; font-size: 10px; background: #ffffff; color: #000000; border: 1 solid #AAAAAA; }
        .formbutton { font-family: Verdana,Tahoma,Arial; color: #004BAB; font-size:13px; font-weight: bold; background-color: #ffffff; border: 1 solid #004BAB; }
        .formreset { font-family: Verdana,Tahoma,Arial; color: #004BAB; font-size:11px; background-color: #ffffff; border: 1 solid #004BAB; }
        .formcombo { font-family: Verdana,Tahoma,Arial; font-size: 11px; background: #efefef; color: #000000; border: 1; }
        .formradio { font-family: Verdana,Tahoma,Arial; font-size: 11px; color: #777777; }
        .formcheckbox { font-family: Verdana,Tahoma,Arial; font-size: 11px; color: #777777; }
        .formtextonly { font-size: 11px; }
    </style>
</head>
<body>

<?

   
include "form.inc.php";
   
   
// Creating the new form
    // Parameters are: <title>, <form name>, <FORM_METHOD_POST|FORM_METHOD_GET>, <action>
   
$form = new form("Formulario de prueba", "myform", FORM_METHOD_POST, "kk.php");
   
   
// Adding three different groups of fields
    // Parameters for addGroup are: <group internal name>, <group title>
   
$form->addGroup ("personal", "Información personal");
   
$form->addGroup ("contacto", "Información de contacto");
   
$form->addGroup ("otros", "Otros");

   
// Adding some fields to the groups
    // Parameters for addElement are: <group internal name on wich to include>, <element object>
    // Where <element object> could be one of these, with its sintaxes:
    // form_element_text (<field title>, <input name>, <default value>, <CSS style name>, <length>, <maxlength>, <0|1 Is or not a read-only field>)
    // form_element_onlytext (<field title>, <text to show>, <CSS style name>)
    // form_element_password (<field title>, <input name>, <default value>, <CSS style name>, <length>, <maxlength>)
    // form_element_combo (<field title>, <input name>, <default value>, <CSS style name>, <combo size>, <array of values>, <0|1 Whether or not this combo allows multiple selections>) Where <array of values> is a hash-array like array ("title" => "value", "title" => "value" ...)
    // form_element_radio (<field title>, <input name>, <default value>, <CSS style name>, <combo size>, <array of values>) Where <array of values> is a hash-array like array ("title" => "value", "title" => "value" ...)
    // form_element_checkbox (<field title>, <input name>, <default value>, <CSS style name>)
    // form_element_textarea (<field title>, <input name>, <default value>, <CSS style name>, <number of columns>, <number of rows>)
    // form_element_hidden (<input name>, <value>)
   
$form->addElement ("personal", new form_element_text ("nombre", "nombre", "", "forminput", 20, 255, 0));
   
$form->addElement ("personal", new form_element_text ("apellidos", "apellidos", "", "forminput", 40, 255, 0));
   
$form->addElement ("personal", new form_element_combo ("sexo", "sexo", "M", "formcombo", 0, array ("H" => "Masculino", "M" => "Femenino"), 1));

   
$form->addElement ("contacto", new form_element_radio ("contactar por", "contactarpor", "1", "formradio", 0, array ("0" => "Teléfono", "1" => "EMail")));
   
$form->addElement ("contacto", new form_element_text ("nombre", "nombre", "", "forminput", 20, 255, 0));
   
$form->addElement ("contacto", new form_element_checkbox ("¿si o no?", "siono", true, "formcheckbox"));
   
   
$form->addElement ("otros", new form_element_textarea ("observaciones", "observaciones", "", "formtextarea", 40, 3));
   
$form->addElement ("otros", new form_element_text ("nombre", "nombre", "", "forminput", 20, 255, 0));
   
$form->addElement ("otros", new form_element_text ("nombre", "nombre", "", "forminput", 20, 255, 0));

   
// Adding a hidden field
   
$form->addElement (FORM_GROUP_HIDDEN, new form_element_hidden ("a", "value for a"));
   
   
// Showing the form
   
echo $form->getform ();
   
   
// There are a few public variables inside the object form that could be changed,
    // This ones are self-explaining: title_bgcolor, title_style, group_bgcolor, group_style, element_bgcolor, element_style, submit_bgcolor, submit_title, submit_style, reset_title, reset_style
    // And this others:
    // element_separator: Contains wathever HTML code wich will be included to separate the field names from the values.
    // issubmit: Wether or not to show the submit button
    // isreset: Wether or not to show the reset fields button

?>

</body>
</html>