Login   Register  
PHP Classes
elePHPant
Icontem

File: simple_example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Arturs Sosins  >  Auto form  >  simple_example.php  >  Download  
File: simple_example.php
Role: Example script
Content type: text/plain
Description: Example with multiple forms on one page
Class: Auto form
Generate HTML forms to manipulate MySQL records
Author: By
Last change: credits changed
Date: 2011-04-25 12:41
Size: 1,714 bytes
 

Contents

Class file image Download
<?php
/*************************************************************
 * This script is developed by Arturs Sosins aka ar2rsawseen, http://webcodingeasy.com
 * Fee free to distribute and modify code, but keep reference to its creator
 *
 * Auto form class can generate simple update, insert, select and delete 
 * HTML forms, form validation and form processing programmatically
 * based on information from mysql table
 *
 * For more information, examples and online documentation visit: 
 * http://webcodingeasy.com/PHP-classes/Generate-forms-programmatically
**************************************************************/
ob_start();
//database connection
include("./connection.php");

//form class
include("./auto_form.php");

//on success

function success($result)
{
    if(
$result === false)
    {
        echo 
"<p>No connection</p>";
    }
    else if(
$result === 0)
    {
        echo 
"<p>No id generated</p>";
    }
    else
    {
        echo 
"<p>New id is ".$result."</p>";
    }
}

$form = new auto_form($serverlink);
$form->debug();

//exclude table columns
$ex = array("ID");

//language array
$lang = array(
    
"int" => "Integer""decimal" => "Decimal"
    
"double" => "Float""text" => "Text"
    
"bool" => "Checkbox""enum" => "Select"
    
"set" => "Multiple select""varchar" => "Default");
$form->set_language($lang);

//set on success function
$form->set_onsuccess("success");

//insert form
echo "<fieldset>";
echo 
"<legend>Insert form</legend>";
$form->insert_form("test_table"$ex);
echo 
"</fieldset>";

//update form
echo "<fieldset>";
echo 
"<legend>Update form</legend>";
$form->update_form("test_table""WHERE ID = '1'"$ex);
echo 
"</fieldset>";
ob_end_flush();
?>