Login   Register  
PHP Classes
elePHPant
Icontem

File: help.txt

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Andrea Bersi  >  Forms generator for MYSQL  >  help.txt  >  Download  
File: help.txt
Role: Documentation
Content type: text/plain
Description: help file
Class: Forms generator for MYSQL
Generate forms to edit MySQL table records
Author: By
Last change:
Date: 2006-04-25 06:12
Size: 3,592 bytes
 

Contents

Class file image Download
For use the class it is necessary to:
1) create a tree as
    
    your_site
    |------template
    |       |--template.tpl
    |       |--template2.txt
    |       |--template3.tpl
    |
    |-------class
    |       |--arial.ttf  (NB: this file in not in the package)
    |       |--calendar.core.js
    |       |--form.class.php
    |       |--db.conf.php
    |       |--captcha_xxx_124.php
    |       |--captcha.class.php
    |
    |-------index.php
    |-------index2.php
    |-------index3.php
    |-------stop.php
    |-------getresult.php
    
    NB: the file arial.ttf is not in the package. You need to copy from your font directory.

2) edit the file /class/db.conf.php and insert yor data for access to mysql database server
3) launch the db.sql: the script create the table example.
4) open in your webserver (i.e.:localhost) the file index.

The script work with this features:
if you call a page withut a querystring, the code create a new record in the table you set.
If you call the page with a querystring (name of the key field and your value, example index.php?id=1) the cpde update the value of the selected record

For build a query you need
//insert the db code
require_once("class/db.conf.php");

//insert the class code
require_once("class/form.class.php");

//create instance
$Modulo = new Form();

//set the table for work
$Modulo->table="tb_prova";

//set the name of the form
$Modulo->FormName="form1";

//set the html code after the label
$Modulo->labelBreak="</td><td>";

//activate the javascript validation (client side)
$Modulo->validation_client_side=true;

//set the value of the field and if the field is required (this feature with the string Needed as last argument)
$Modulo->labelField("note","Notes","Needed") ;

.... for each field

//set up regular expressions for field validation
$Modulo->registerValidation("required",".+","The field is needed");

.... for each method you want

//apply the validation method to the fields: in this example you want to validate the field note, using the method named "required" and if the validation not suces you print a text as you set in the last argument
$Modulo->validatejava("regExp","note","required","Notes: The field is needed!");

..... for each field you want


//this method load the values (Don't modify)
$campo=$Modulo->carica_valori($_REQUEST[$Modulo->campo_chiave]);

//this method perform the insert/update in the db ONLY if the server validation is succes
$id_record=$Modulo->elaboraForm();

//if not any error you get a success and you work any other code: a echo message or you send an mail 
if ($Modulo->success)
{
    echo "OK";//code if the success insert
    mail (......);
    header("location...);
}

//add the input html field with the add_campi method
$Modulo->add_campi("Note","Text_Area",
                    array(
				"name"=>"note",
				"val"=> $campo['note'],
				"rows"=>"10",
				"cols"=>"80")) ;
// THE METHOD require 3 argument: the first is the name of the text to replace in the template file
// the second is the type of HTML field you want (see the documentation class for alla forms input);
// the last argument is an array: the name, the value of the field is created (see the example)

.... for each html input you want


//add a string to the template to replace the tag named pippo
$Modulo->add_php("pippo","This is a test string");

//finally create the form with the render method: the name of the template is needed
$Modulo->render("template/template.tpl");