PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Oleg KronuS   Simple Form builder   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Simple example
Class: Simple Form builder
Compose and generate HTML forms
Author: By
Last change:
Date: 12 years ago
Size: 4,391 bytes
 

 

Contents

Class file image Download
<!DOCTYPE html>
<html lang="ru">
    <head>
        <meta charset="utf-8" />
        <title>Form builder</title>
        <style type="text/css">
            fieldset {
                border: none;
            }
            textarea {
                height: 100px;
                width: 300px;
            }
            .clearfix {
                clear: both;
            }
            .kqc-form-element-wrapper {
                padding: 5px;
            }
            .inline .kqc-label-wrapper {
                float: left;
                padding-right: 10px;
            }
            .inline2 {
                float: left;
            }
            .kqc-required-field {
                color: red;
            }
        </style>
    </head>
    <body>
        <?php

       
require_once('class.form_builder.php');
        require_once(
'class.form_item.php');
        require_once(
'class.form_item_textarea.php');
        require_once(
'class.form_item_input.php');
        require_once(
'class.form_item_select.php');

       
$form = new form_builder();
       
$form->set_enctype('multipart/form-data');
       
$form->set_method('post');

       
$input = new form_item_input();
       
$input->set_label('First Name')->set_type('text')->set_default_value('first name')->set_attr_array(array('name'=>'first_name', 'id'=>'first_name'))->set_required(true)->add_wrapper_class_array(array('inline2'));
       
$form->add_field($input);

       
$input = new form_item_input();
       
$input->set_label('Last Name')->set_type('text')->set_default_value('last name')->set_attr_array(array('name'=>'last_name', 'id'=>'last_name'))->set_required(true);
       
$form->add_field($input);

       
$select = new form_item_select();
       
$select->set_label('Country')->set_attr_array(array('name'=>'select2[]', 'id'=>'select2'))->set_option('1', '3')->set_options_array(array('0'=>'not selected', '1'=>'Denmark', '2'=>'Turkey', '3'=>'China'))->set_default_value(2);
       
$form->add_field($select);

       
$input = new form_item_input();
       
$input->set_label('Photo')->set_type('file')->set_attr_array(array('name'=>'photo', 'id'=>'photo'))->add_wrapper_class('inline');
       
$form->add_field($input);

       
$input = new form_item_input();
       
$input->set_label('Date')->set_type('date')->set_attr_array(array('name'=>'date', 'id'=>'date'))->add_wrapper_class('inline');
       
$form->add_field($input);

       
$input = new form_item_input();
       
$input->set_label('Male')->set_type('radio')->set_default_value('male')->set_attr_array(array('name'=>'radio1', 'id'=>'radio1'))->add_wrapper_class('inline')->add_wrapper_class_array(array('inline', 'inline2'));
       
$form->add_field($input);

       
$input = new form_item_input();
       
$input->set_label('Female')->set_type('radio')->set_default_value('female')->set_attr_array(array('name'=>'radio1', 'id'=>'radio2', 'checked'=>'checked'))->add_wrapper_class_array(array('inline', 'inline2'));
       
$form->add_field($input);

       
$input = new form_item_input();
       
$input->set_label('Other')->set_type('radio')->set_default_value('other')->set_attr_array(array('name'=>'radio1', 'id'=>'radio3'))->add_wrapper_class_array(array('inline', 'inline2'));
       
$form->add_field($input);

       
$textarea = new form_item_textarea();
       
$textarea->set_label('CV')->set_default_value('My CV')->set_required(true)->set_attr_array(array('name'=>'cv', 'id'=>'cv'))->add_wrapper_class('clearfix');
       
$form->add_field($textarea);

       
$input = new form_item_input();
       
$input->set_label('I need your spam')->set_type('checkbox')->set_attr_array(array('name'=>'checkbox1', 'id'=>'checkbox1'))->add_wrapper_class_array(array('inline'));
       
$form->add_field($input);

       
$input = new form_item_input();
       
$input->set_type('reset')->set_default_value('Reset')->set_attr_array(array('name'=>'reset', 'id'=>'reset'))->add_wrapper_class('inline2');
       
$form->add_field($input);

       
$input = new form_item_input();
       
$input->set_type('submit')->set_default_value('Submit')->set_attr_array(array('name'=>'submit', 'id'=>'submit'))->add_wrapper_class('inline2');
       
$form->add_field($input);

        echo
$form->compile();
       
?>
</body>
</html>