PHP Classes

File: example1_with_template.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in Bookmark in
  Classes of sameer shelavale  >  X2Form  >  example1_with_template.php  >  Download  
File: example1_with_template.php
Role: Example script
Content type: text/plain
Description: customizing the layout of Quidich Form in Example1
Class: X2Form
Show and validate HTML forms defined in XML files
Author: By
Last change: changed file paths as folder structure is not permitted on phpclasses
Date: 3 years ago
Size: 2,275 bytes


Class file image Download
 * Author: Sameer Shelavale
 * Email:,
 * Author website:
 * Phone: +91 9890103122
 * License: AGPL3, You should keep Package name, Class name, Author name, Email and website credits.
 * For other type of licenses please contact the author.
 * PHP Version: Tested on PHP 5.2.2 & 5.3.10
 * Copyrights (C) 2012 Sameer Shelavale

require_once( 'X2Form.php' );
'X2FormElement.php' );
'class.dbhelper.php' );
'class.logger.php' );

$link = mysql_connect('localhost', 'root', '');
if (!
$link) {
'Could not connect: ' . mysql_error());
$db_selected = mysql_select_db('test', $link);
if (!
$db_selected) {
    die (
'Can\'t select database : ' . mysql_error());

//FIRST_NAME, LAST_NAME and PROFESSION is populated from xml
$formObj = new X2Form( 'DiamondForm', 'xmlfile', 'quidich_form_populated.xml', 'sample_template.html' );

//we can also populate fieds from php using setFormValues() method of the X2Form class
$values = array('BROOMSTICKS'=>array('nimbus2001', 'firebolt'),
'MATCHES_PLAYED'=>'11-25' );

$formObj->setFormValues( $values );

//Alternatively we can also populate individual fields directly
$formObj->elements['HOUSE']->value = '1'; //arary syntax
$formObj->elements->INTRO->value = "I am a Harry... Harry Potter!"; //this syntax works as well

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Diplaying a Form using X2Form</title>
    <link href="style.css" type="text/css" rel="stylesheet">
    <div id="container">
        <h1>Example 1: X2Form Form Generator</h1>
        <h3>Displaying form stored in <a href="forms/quidich_form.xml">xml file</a></h3>
        <?php echo $formObj->render(); ?>