Location: PHPKode > scripts > Meta Builder > index2.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Form Builder</title>
    <meta http-equiv="Content-Language" content="English" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

    <!-- Include Core CSS Files -->
    <link rel="stylesheet" type="text/css" href="html/css/lib/Builder.css" media="screen" />
    <link rel="stylesheet" type="text/css" href="html/css/lib/validationEngine.jquery.css" media="screen" />

    <!-- Include Core Javascript Files -->
    <script src="html/javascript/lib/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="html/javascript/lib/jquery.validationEngine.js" type="text/javascript"></script>
    <script src="html/javascript/lib/grid.js" type="text/javascript"></script>
    <script src="html/javascript/lib/form.js" type="text/javascript"></script>
</head>

<body>

<div id="wrapper">
<?php

// Load the Builder Library
include 'includes/Builder.php';
include 'includes/builder/Helper.php';


try
{
    // Create our first name field
    $oElement1 = new BuilderHelperElement('FirstName');
    $oElement1->SetValidation(new BuilderHelperValidation(array('match' => 'onlyLetter', 'required' => true)))
              ->SetHint('First Name');

    // Create our last name field
    $oElement2 = new BuilderHelperElement('LastName');
    $oElement2->SetValidation(new BuilderHelperValidation(array('match' => 'onlyLetter', 'required' => true)))
               ->SetHint('Last Name')->SetDescription(', ');

    // Create a new row for our first and last name fields
    $oRow1 = new BuilderHelperRow('Name', '16x16/home.png');
    $oRow1->AddElement($oElement2);
    $oRow1->AddElement($oElement1);

    // Build a list for our title field
    $oList = new BuilderHelperList();
    $oList->AddListItem(new BuilderHelperListItem('Mr.', 'Mr.', '16x16/gender-male.png'));
    $oList->AddListItem(new BuilderHelperListItem('Mrs.', 'Mrs.', '16x16/gender-female.png'));
    $oList->AddListItem(new BuilderHelperListItem('Ms.', 'Ms.', '16x16/gender-female.png'));
    $oList->AddListItem(new BuilderHelperListItem('Prof.'));
    $oList->AddListItem(new BuilderHelperListItem('Dr.'));

    // Build our title list field
    $oElement3 = new BuilderHelperElement('Title', 'list');
    $oElement3->SetRenderMode('radio')->SetList($oList)->SetDescription('Please select your title');

    // Build a row for our title list field
    $oRow2 = new BuilderHelperRow('Title');
    $oRow2->AddElement($oElement3);

    // Build a submit button
    $oElement4 = new BuilderHelperElement('Action', 'submit');
    $oElement4->SetValue('Add New Account');

    // Build a row for our submit button
    $oRow3 = new BuilderHelperRow();
    $oRow3->AddElement($oElement4);

    // Combine all our rows
    $oRowsHelper = new BuilderHelperRows();
    $oRowsHelper->AddRow($oRow1);
    $oRowsHelper->AddRow($oRow2);
    $oRowsHelper->AddRow($oRow3);

    // Add our rows to a group with it's own heading and sub heading
    $oGroupHelper = new BuilderHelperGroup();
    $oGroupHelper->SetHeading('Test Group')->SetSubheading('SubHeading Test');
    $oGroupHelper->SetRows($oRowsHelper);

    // Combine our groups
    $oGroupsHelper = new BuilderHelperGroups();
    $oGroupsHelper->AddGroup($oGroupHelper);

    // Add our groups to our form helper and set some basic attributes
    $oFormHelper = new BuilderHelperForm('test-form');
    $oFormHelper->SetCopy('This is an example using the helper class.')->AddGroups($oGroupsHelper)->SetScript('index2.php');
    
    // Build our form
    $oForm = new BuilderForm();
    echo $oForm->Render($oFormHelper->ToArray());

    // Change the Identity and then access an element directly to change it's rendering mode
    $oFormHelper->SetIdentity('test-form-2')->Groups->{0}->Rows->{1}->Element[0]->SetRenderMode('select');
    
    // Render the new modified form
    echo $oForm->Render($oFormHelper->ToArray());
}
catch (Exception $oException)
{
    echo $oException->GetMessage();
}

?>
</div>

</body>
</html>
Return current item: Meta Builder