Skip to content

Instantly share code, notes, and snippets.

@lucas1
Last active December 18, 2015 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucas1/5736372 to your computer and use it in GitHub Desktop.
Save lucas1/5736372 to your computer and use it in GitHub Desktop.

Class Form Documentation

Description

Class Form - XML Generator for DHTMLX

construct

$form = new Form( set encoding, default utf-8 )

$form = new Form;

or

$form = new Form('iso-8859-1');

item

$form->item( array( 'key attribute' => 'value attribute' ) )

settings

$form->item(
    array(
        "type" => "settings",
        "labelWidth" => 90
    )
);

input

$form->item(
    array(
        "type" => "input",
        "name" => "foo",
        "label" => "Foo"
    )
);

button

$form->item(
    array(
        "type" => "button",
        "value" => "Button"
    )
);

select

$form->item(
    array(
        "type" => "select",
        "name" => "bar",
        "label" => "Bar",
        "option" => array(
            array("text" => "Admin", "value" => "admin"),
            array("text" => "User", "value" => "user", "selected" => "true")
        )
    )
);

note

$form->item(
    array(
        "type" => "input",
        "name" => "foo",
        "label" => "Foo",
        "note" => "value"
    )
);

or

$form->item(
    array(
        "type" => "input",
        "name" => "foo",
        "label" => "Foo",
        "note" => array(
            "width" => 150,
            "text" => "value"
        )
    )
);

start and end

$form->start( array( 'key attribute' => 'value attribute' ) ) and $form->end()

settings

$form->start(
    array(
        "type" => "settings",
        "labelWidth" => 90
    )
);

$form->item(
    array(
        "type" => "input",
        "name" => "foo",
        "label" => "Foo"
    )
);

$form->item(
    array(
        "type" => "select",
        "name" => "bar",
        "label" => "Bar",
        "option" => array(
            array("text" => "Admin", "value" => "admin"),
            array("text" => "User", "value" => "user", "selected" => "true")
        )
    )
);

$form->end();

option

$form->option( array( 'key attribute' => 'value attribute' ) )

select

$form->start(
    array(
        "type" => "select",
        "name" => "bar",
        "label" => "Bar"
    )
);

$form->option(
    array("value" => "1", "text" => "Option 1"),
    array("value" => "2", "text" => "Option 2"),
    array("value" => "3", "text" => "Option 3"),
    array("value" => "4", "text" => "Option 4")  
);

$form->end();

header

$form->header()

$form->header();

return

header("Content-type: application/xml; charset=utf-8");

result

$form->result()

echo $form->result();

Print XML

Examples

Example 1

Mode 1

<?php
include_once 'DHX.php';

$form1 = new Form();

$form1->item(
    array(
        "type" => "settings",
        "position" => "label-right",
        "item" => array(
            array(
                "type" => "fieldset",
                "inputWidth" => 240,
                "label" => "Login and Senha",
                "item" => array(
                    array(
                        "type" => "input", 
                        "name" => "login", 
                        "inputWidth" => 200, 
                        "label" => "Login"
                    ),
                    array(
                        "type" => "password", 
                        "name" => "password", 
                        "inputWidth" => 200, 
                        "label" => "Password"
                    )
                )
            )
        )
    )
);

$form1->header();
echo $form1->result();
?>

Result

<?xml version="1.0" encoding="utf-8"?>
<items>
    <item type="settings" position="label-right">
        <item type="fieldset" inputWidth="240" label="Login and Senha">
            <item type="input" name="login" inputWidth="200" label="Login"/>
            <item type="password" name="password" inputWidth="200" label="Password"/>
        </item>
    </item>
</items>

Mode 2

<?php
include_once 'DHX.php';

$form2 = new Form('iso-8859-1'); // set encoding iso-8859-1, default utf-8

// start settings
$form2->start(
    array(
        "type" => "settings",
        "position" => "label-right"
    )
);

// start fieldset
$form2->start(
    array(
        "type" => "fieldset",
        "inputWidth" => 240,
        "label" => "Login and Senha",
    )
);

// login and password
$form2->item(
    array(
        "type" => "input",
        "name" => "login",
        "inputWidth" => 200,
        "label" => "Login"
    ),
    array(
        "type" => "password",
        "name" => "password",
        "inputWidth" => 200,
        "label" => "Password"
    )
);

$form2->end(); // end fieldset
$form2->end(); // end settings

$form2->header();
echo $form2->result();
?>

Result

<?xml version="1.0" encoding="iso-8859-1"?>
<items>
    <item type="settings" position="label-right">
        <item type="fieldset" inputWidth="240" label="Login and Senha">
            <item type="input" name="login" inputWidth="200" label="Login"/>
            <item type="password" name="password" inputWidth="200" label="Password"/>
        </item>
    </item>
</items>

Example 2

Mode 1

<?php
include_once 'DHX.php';

$form1 = new Form();

$form1->item(
    array(
        "type" => "settings",
        "position" => "label-right",
        "item" => array(
            array(
                "type" => "fieldset",
                "inputWidth" => 240,
                "label" => "Select",
                "item" => array(
                    array(
                        "type" => "select",
                        "name" => "select",
                        "label" => "Select",
                        "option" => array(
                            array("value" => "1", "text" => "Option 1"),
                            array("value" => "2", "text" => "Option 2"),
                            array("value" => "3", "text" => "Option 3"),
                            array("value" => "4", "text" => "Option 4")
                        )
                    )
                )
            )
        )
    )
);

$form1->header();
echo $form1->result();
?>

Result

<?xml version="1.0" encoding="utf-8"?>
<items>
    <item type="settings" position="label-right">
        <item type="fieldset" inputWidth="240" label="Select">
            <item type="select" name="select" label="Select">
                <option value="1" text="Option 1"/>
                <option value="2" text="Option 2"/>
                <option value="3" text="Option 3"/>
                <option value="4" text="Option 4"/>
            </item>
        </item>
    </item>
</items>

Mode 2

<?php
include_once 'DHX.php';

$form2 = new Form('iso-8859-1'); // set encoding iso-8859-1, default utf-8

// start settings
$form2->start(
    array(
        "type" => "settings",
        "position" => "label-right"
    )
);

// start fieldset
$form2->start(
    array(
        "type" => "fieldset",
        "inputWidth" => 240,
        "label" => "Select",
    )
);

// start select
$form2->start(
    array(
        "type" => "select",
        "name" => "select",
        "label" => "Select"
    )
);

$form2->option(
    array("value" => "1", "text" => "Option 1"),
    array("value" => "2", "text" => "Option 2"),
    array("value" => "3", "text" => "Option 3"),
    array("value" => "4", "text" => "Option 4")
);

$form2->end(); // end select
$form2->end(); // end fieldset
$form2->end(); // end settings

$form2->header();
echo $form2->result();
?>

Result

<?xml version="1.0" encoding="iso-8859-1"?>
<items>
    <item type="settings" position="label-right">
        <item type="fieldset" inputWidth="240" label="Select">
            <item type="select" name="select" label="Select">
                <option value="1" text="Option 1"/>
                <option value="2" text="Option 2"/>
                <option value="3" text="Option 3"/>
                <option value="4" text="Option 4"/>
            </item>
        </item>
    </item>
</items>

Author

Lucas Tiago de Moraes

Support

Group DHTMLX Facebook

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment