PHP Classes

File: sample_form_creation.php

Recommend this page to a friend!
  Classes of Josť M. Carnero   Formulario   sample_form_creation.php   Download  
File: sample_form_creation.php
Role: Example script
Content type: text/plain
Description: Form creation
Class: Formulario
Generate and validate HTML forms
Author: By
Last change: better documentation and better example
Date: 14 years ago
Size: 2,402 bytes


Class file image Download
must be in "head" (or pior) section of the page; validations in javascript: $this->aFormulario['frmValidar']
and "$oForm->pintaFormulario();" where the form will be ("body" section of the page)

debe iniciarse en la seccion "head" (html) de la pagina o antes, para poder meter las validaciones ($this->aFormulario['frmValidar']) en esa seccion
ejemplo de uso:


//this array contains expecifications for the fields of the form
$aCampos = array(
//'id/name/ddbb_field' => array('properties' => 'type validation obligatory field_length', 'title' => 'Human readable Title: '),
'titulo' => array('propiedades' => 'text - 1 100', 'titulo' => 'T&iacute;tulo: '),
'texto' => array('propiedades' => 'textarea - 0 16000000', 'titulo' => 'Texto: '),
'fichero' => array('propiedades' => 'file', 'titulo' => 'Fichero: '),
'tipo' => array('propiedades' => 'select', 'titulo' => 'Tipo: ', 'valores' => array('' => 'ninguno', '0' => 'cero', '1' => 'uno', '2' => 'dos', '3' => 'tres')),
'activa' => array('propiedades' => 'checkbox', 'titulo' => 'Activa: ')

$oForm = form_sel('tabla'); //is possible too: $oForm = new formulario();
$oForm->sRutaFicheros = 'img/'; //path to save uploaded files
//$oForm->sQueryTabla = 'tabla_ej'; //table name for insertion/update/delete in a database
//$oForm->sRowId = 'id'; //primary key name for update/delete records
//$oForm->sRowIdVal = $sId; //primary key value of actual record
$oForm->sAction = 'sample_form_procesing.php';

$oForm->creaFormulario($aCampos); //internal construction of the form
<title>Sample form</title>
//"$sScriptsJS" contains javascript validations for the form, must echoed in the "head" section of the page
//la variable "$sScriptsJS" debe pintarse en la cabecera de la pagina (<head>), con lo cual el formulario debe iniciarse y crearse antes
$sScriptsJS = '<script type="text/javaScript" src="eventos.js"></script>'; //events functions for unobstrusive javascript
$sScriptsJS .= '<script type="text/javaScript" src="class.formulario.js"></script>'; //javascript functions for validations
$sScriptsJS .= $oForm->aFormulario['frmValidar']; //all the javascript code for validations of the form
->pintaFormulario(); //write the form, "echo"
//echo($oForm->sError); //show errors