Sweden Democrats' Meeting Tool
 All Classes Files Functions Variables Pages
Public Member Functions | Static Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
SD_Form Class Reference

SD_Forms is a XHTML form class that handles: creation, display and validation of form elements and complete form layouts. More...

Public Member Functions

 __construct ($options=array())
 make_id ($options)
 start ()
 stop ()
 make_label ($options)
 make_description ($options)
 make_input ($options)
 add_section ($section)
 use_post_value (&$input, $post_data=null)
 add_section_input ($section, $input, $settings, $post_data=null)
 add_text_section ($sectionName, $text)
 add_layout ($layouts, $inputData, $settings, $postData=null)
 display ()
 validate_post ($inputs, $inputs_to_check, $values)
 l ($string, $replacementString=array())

Static Public Member Functions

static get_post_data ($callingClass, $POST=null)
static fix_name ($name)
static make_name ($options)
static generate_changed_sql ($inputs, $inputsToChange, $tableName, $uniqueKey, $oldValues, $newValues)
static valid_email ($email)

Protected Attributes

 $language_data = array()

Private Member Functions

 make_required_field ($options)
 make_validation ($options)
 implode_array ($data, &$strings, $glueBefore, $glueAfter, $stringPrefix=null, $currentString=null)

Private Attributes

 $options
 $default_options
 $sections = array()

Detailed Description

SD_Forms is a XHTML form class that handles: creation, display and validation of form elements and complete form layouts.

    Form handling class
    -------------------
Using the class

First, create the class:

$form = new SD_Forms();

During your display of the HTML:

echo $form->start();

Now you can build your forms using arrays as inputs.

$input_text = array(
  'name' => 'my_text_example',
  'type' => 'text',
  'size' => 60,  // recommended that you have any size specified
  'css_class' => 'text_area_orange',  // optional
  'css_style' => 'font-size: 500%;',  // optional
  'value' => 'This is the default text displayed', // optional
  'description' => 'This is a short, optional description. Note that you'll need to put divs around the description in order to do interesting stuff with it.',
);
echo $form->make_label( $input_text ); // The accessible label
echo $form->make_input( $input_text ); // The input itself
echo $form->make_description( $input_text ); // displays only the description, including validation info.

And to finish up the form after displaying:

echo $form->stop();
Input types

Most of the input types have the css_class, css_style, description, value fields in common. checkbox

$input_checkbox = array(
  'name' => 'checkbox_example',
  'type' => 'checkbox',
  'label' => 'Label of checkbox',
  'checked' => true,
);

value, description is optional.

            file
$input_file = array(
  'name' => 'file_example',
  'type' => 'file',
  'value' => 'Text on button',
);
            image

An image is used instead of a submit button.

$input_image = array(
  'name' => 'image_example',
  'type' => 'image',
  'label' => 'ALT value of image'
  'src' => 'images/submit.png',
);
            password

Similar to text, except that the value isn't displayed.

$input_password = array(
  'name' => 'password_example',
  'type' => 'password',
  'label' => 'Displayed label',
);
            radio
$input_radio = array(
  'name' => 'radio_example',
  'type' => 'radio
  'label' => 'Label of radio box',
  'options' => array(
    'option001' => 'First radio option',
    'option002' => 'Second radio option',
  ),
);
            select
$input_select = array(
  'name' => 'select_example',
  'type' => 'select',
  'label' => 'Label of select',
  'multiple' => false,  // Allow selection of multiple values
  'size' => 5,  // How many option rows to display.
  'options' => array(
    'option001' => 'First select option',
    'option002' => 'Second select option',
  ),
);
            submit
$input_submit = array(
  'name' => 'submit_example',
  'type' => 'submit',
  'value' => 'Displayed on the button',
);
            text
$input_text = array(
  'name' => 'text_example',
  'type' => 'text
  'label' => 'Label of text box',
);
            textarea
$input_textarea = array(
  'name' => 'textarea_example',
  'type' => 'textarea',
  'label' => 'Label of text area',
  'rows' => 80,
  'cols' => 10,
);
Validation

To add validation to your input, add a key called validation and make it an array with any of the following keys:

    empty                   Field is allowed to be empty
    valuemin                Integer value: minimum
    valuemax                Integer value: maximum
    datetime                Date must be in this format. (Use format keywords from date(). "Y-m-d").
    datemaximum             Latest date/time allowed. Any date() format.
    lengthmin               Length: minimum

Validation example:

$input_text = array( 'name' => 'text_example', 'type' => 'text 'label' => 'Label of text box', 'validation' => array( 'empty' => true, ), );

Changelog
Author
Edward Plainview edwar.nosp@m.d.pl.nosp@m.ainvi.nosp@m.ew@s.nosp@m.verig.nosp@m.edem.nosp@m.okrat.nosp@m.erna.nosp@m..se

Constructor & Destructor Documentation

SD_Form::__construct (   $options = array())

Member Function Documentation

SD_Form::add_layout (   $layouts,
  $inputData,
  $settings,
  $postData = null 
)

Adds sections + inputs "automatically".

Using $layout, the modules $settings module and the postdata, it creates a form with section and inputs.

Example layout

private $inputLayout = array( 0 => array( 'name' => 'ExampleSection', 'description' => 'This section deals with examples. Examples are good.', 'autoinputs' => array( 'IFACMS_STAGE_PAGE_TITLE_SEPARATOR' => array('text'), ), // Inputs 'inputs' => array( array( 'type' => 'submit', 'name'=>'CHANGE_SETTINGS_BASE', 'value' => 'Change settings', ) ), // Manualinputs ), // 0 ); // inputLayout

Tip: If your module requires several pages/tabs of settings, put the layouts in one big layoutarray and make the tab name the key.

SD_Form::add_section (   $section)

Adds a section.

$section = array( 'name' => 'Name of the section', 'description' => 'Section description that tells the user what this section is about.', 'inputs' => RESERVED )

SD_Form::add_section_input (   $section,
  $input,
  $settings,
  $post_data = null 
)

Adds an input to a section. Kinda like makeInput, but with a section name.

SD_Form::add_text_section (   $sectionName,
  $text 
)
SD_Form::display ( )

Displays a whole form with sections and all the section inputs.

static SD_Form::fix_name (   $name)
static

Cleans up the name of an input, remove illegal characters.

static SD_Form::generate_changed_sql (   $inputs,
  $inputsToChange,
  $tableName,
  $uniqueKey,
  $oldValues,
  $newValues 
)
static

Generates an SQL-statement that either updates or inserts the values into a table.

On an update, it only changes the values that have changed (compares newvalues to oldvalues).

Parameters
$inputsarray An array of inputs in standard input format (see top).
$inputsToChangearray An array of names of which inputs to change.
$tableNamestring The table's name.
$uniqueKeystring The unique key column name.
$oldValuesarray Associative array of old values.
$newValuesarray Associative array of new values.
Returns
string Prepared SQL string.
static SD_Form::get_post_data (   $callingClass,
  $POST = null 
)
static

Returns the _POST data of the calling class.

SD_Form::implode_array (   $data,
$strings,
  $glueBefore,
  $glueAfter,
  $stringPrefix = null,
  $currentString = null 
)
private
SD_Form::l (   $string,
  $replacementString = array() 
)

Returns the translated string, if any.

SD_Form::make_description (   $options)

Returns the description of this input.

SD_Form::make_id (   $options)

Returns a text ID of this input.

SD_Form::make_input (   $options)

Makes an input string.

SD_Form::make_label (   $options)

Returns the label of this input.

static SD_Form::make_name (   $options)
static

Returns the name of this input.

SD_Form::make_required_field (   $options)
private

Makes a small asterisk thingy that is supposed to symbolise that the field is required.

SD_Form::make_validation (   $options)
private
SD_Form::start ( )

Returns a simple <form> tag (with action and method set).

SD_Form::stop ( )

Returns </form>. That's it.

SD_Form::use_post_value ( $input,
  $post_data = null 
)
static SD_Form::valid_email (   $email)
static

Validate an email address.

Parameters
$email$email Email address to validate
Returns
bool True, if the address is valid.
SD_Form::validate_post (   $inputs,
  $inputs_to_check,
  $values 
)

Validates the values based on $inputs and which of the $inputs to check.

Returns an array of $key / 'error message' if validation fails, else returns true.

Member Data Documentation

SD_Form::$default_options
private
Initial value:
array(
'class' => '',
'global_nameprefix' => '',
'nameprefix' => '',
'namesuffix' => '',
'title' => '',
'alt' => '',
'value' => '',
'multiple' => false,
'size' => 1,
'maxlength' => 255,
'disabled' => false,
'readonly' => false,
'display_two_rows' => false,
'style' => 'STYLE1',
'css_class' => '',
'css_style' => '',
'form_method' => 'post',
'form_action' => '',
'description' => '',
)
SD_Form::$language_data = array()
protected
SD_Form::$options
private
SD_Form::$sections = array()
private

The documentation for this class was generated from the following file: