Login   Register  
PHP Classes
elePHPant
Icontem

File: example1_populate.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of sameer shelavale  >  X2Form  >  example1_populate.php  >  Download  
File: example1_populate.php
Role: Example script
Content type: text/plain
Description: Populating the form in Example1 with XML as well as with PHP
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: 2 years ago
Size: 2,249 bytes
 

Contents

Class file image Download
<?php
/****************************************************************************************************
 * Author: Sameer Shelavale
 * Email: sameer@possible.in, samiirds@gmail.com
 * Author website: http://possible.in
 * Phone: +91 9890103122
 * License: AGPL3, You should keep Package name, Class name, Author name, Email and website credits.
 *             http://www.gnu.org/licenses/agpl-3.0.html
 *             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' );
require_once( 
'X2FormElement.php' );
require_once( 
'class.dbhelper.php' );
require_once( 
'class.logger.php' );

$link mysql_connect('localhost''root''');
if (!
$link) {
    die(
'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'  );

//we can also populate fieds from php using setFormValues() method of the X2Form class 
$values = array('BROOMSTICKS'=>array('nimbus2001''firebolt'),
                
'QMAIL'=>'harry@hogwarts.com',
                
'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" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <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">
</head>
<body>
    <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(); ?>
    </div>
    <br/>
    <br/>
</body>
</html>