Version 0.3.5 beta
This commit is contained in:
200
core/f/form.php
200
core/f/form.php
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
namespace Nibiru\Factory;
|
||||
use Nibiru\Form\TypeButton;
|
||||
use Nibiru\Form\TypeCheckbox;
|
||||
use Nibiru\Form\TypeColor;
|
||||
use Nibiru\Form\TypeDatetime;
|
||||
@@ -7,6 +8,7 @@ use Nibiru\Form\TypeEmail;
|
||||
use Nibiru\Form\TypeFileUpload;
|
||||
use Nibiru\Form\TypeHidden;
|
||||
use Nibiru\Form\TypeImageSubmit;
|
||||
use Nibiru\Form\TypeLabel;
|
||||
use Nibiru\Form\TypeNumber;
|
||||
use Nibiru\Form\TypeOption;
|
||||
use Nibiru\Form\TypePassword;
|
||||
@@ -34,6 +36,7 @@ class Form
|
||||
private static $element;
|
||||
private static $form;
|
||||
private static $option;
|
||||
private static $div = false;
|
||||
|
||||
/**
|
||||
* @desc is used internaly for assambly only
|
||||
@@ -60,6 +63,14 @@ class Form
|
||||
*/
|
||||
private static function assamble( $element )
|
||||
{
|
||||
if( self::getDiv() )
|
||||
{
|
||||
if(is_string(self::getDiv()))
|
||||
{
|
||||
$element = str_replace('ELEMENT', $element, self::getDiv());
|
||||
self::setDiv(false);
|
||||
}
|
||||
}
|
||||
self::$form .= $element;
|
||||
}
|
||||
|
||||
@@ -72,7 +83,40 @@ class Form
|
||||
{
|
||||
return str_replace( 'FIELDS', self::$form, $form );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected static function getDiv( )
|
||||
{
|
||||
return self::$div;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $div
|
||||
*/
|
||||
private static function setDiv( $div = false )
|
||||
{
|
||||
if($div != false)
|
||||
{
|
||||
if( is_array( $div ) )
|
||||
{
|
||||
foreach ( $div as $key=>$selector )
|
||||
{
|
||||
self::$div = '<div ' . $key . '="' . $selector . '">' . "\n" . 'ELEMENT</div>' . "\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
self::$div = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
self::$div = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -94,8 +138,12 @@ class Form
|
||||
* @param $attributes
|
||||
* @return mixed
|
||||
*/
|
||||
public static function addForm( $attributes )
|
||||
public static function addForm( $attributes, $div = false )
|
||||
{
|
||||
if($div)
|
||||
{
|
||||
self::setDiv( $div );
|
||||
}
|
||||
self::setElement( new \Nibiru\Form\Form() );
|
||||
return self::display( self::getElement()->loadElement( $attributes ) );
|
||||
}
|
||||
@@ -104,8 +152,12 @@ class Form
|
||||
* @desc adds an input type Textfield
|
||||
* @param $attributes
|
||||
*/
|
||||
public static function addInputTypeText( $attributes )
|
||||
public static function addInputTypeText( $attributes, $div = false )
|
||||
{
|
||||
if($div)
|
||||
{
|
||||
self::setDiv( $div );
|
||||
}
|
||||
self::setElement( new TypeText() );
|
||||
self::assamble( self::getElement()->loadElement( $attributes ) );
|
||||
}
|
||||
@@ -114,8 +166,12 @@ class Form
|
||||
* @desc adds an input type Submit
|
||||
* @param $attributes
|
||||
*/
|
||||
public static function addInputTypeSubmit( $attributes )
|
||||
public static function addInputTypeSubmit( $attributes, $div = false )
|
||||
{
|
||||
if($div)
|
||||
{
|
||||
self::setDiv( $div );
|
||||
}
|
||||
self::setElement( new TypeSubmit() );
|
||||
self::assamble( self::getElement()->loadElement( $attributes ) );
|
||||
}
|
||||
@@ -124,8 +180,12 @@ class Form
|
||||
* @desc adds an input textarea field with the size of the column and the rows
|
||||
* @param $attributes
|
||||
*/
|
||||
public static function addInputTypeTextarea( $attributes )
|
||||
public static function addInputTypeTextarea( $attributes, $div = false )
|
||||
{
|
||||
if($div)
|
||||
{
|
||||
self::setDiv( $div );
|
||||
}
|
||||
self::setElement( new TypeTextarea() );
|
||||
self::assamble( self::getElement()->loadElement( $attributes ) );
|
||||
}
|
||||
@@ -135,8 +195,12 @@ class Form
|
||||
* more then one
|
||||
* @param $attributes
|
||||
*/
|
||||
public static function addInputTypeRadio( $attributes )
|
||||
public static function addInputTypeRadio( $attributes, $div = false )
|
||||
{
|
||||
if($div)
|
||||
{
|
||||
self::setDiv( $div );
|
||||
}
|
||||
self::setElement( new TypeRadio() );
|
||||
self::assamble( self::getElement()->loadElement( $attributes ) );
|
||||
}
|
||||
@@ -145,8 +209,12 @@ class Form
|
||||
* @desc adds an input type of a Checkbox button, should be a tick more of one
|
||||
* @param $attributes
|
||||
*/
|
||||
public static function addInputTypeCheckbox( $attributes )
|
||||
public static function addInputTypeCheckbox( $attributes, $div = false )
|
||||
{
|
||||
if($div)
|
||||
{
|
||||
self::setDiv( $div );
|
||||
}
|
||||
self::setElement( new TypeCheckbox() );
|
||||
self::assamble( self::getElement()->loadElement( $attributes ) );
|
||||
}
|
||||
@@ -155,8 +223,12 @@ class Form
|
||||
* @desc adds a input field for password entry
|
||||
* @param $attributes
|
||||
*/
|
||||
public static function addInputTypePassword( $attributes )
|
||||
public static function addInputTypePassword( $attributes, $div = false )
|
||||
{
|
||||
if($div)
|
||||
{
|
||||
self::setDiv( $div );
|
||||
}
|
||||
self::setElement( new TypePassword() );
|
||||
self::assamble( self::getElement()->loadElement( $attributes ) );
|
||||
}
|
||||
@@ -165,8 +237,12 @@ class Form
|
||||
* @desc adds a calendar field with the given date value
|
||||
* @param $attributes
|
||||
*/
|
||||
public static function addInputTypeDate( $attributes )
|
||||
public static function addInputTypeDate( $attributes, $div = false )
|
||||
{
|
||||
if($div)
|
||||
{
|
||||
self::setDiv( $div );
|
||||
}
|
||||
self::setElement( new TypeDate() );
|
||||
self::assamble( self::getElement()->loadElement( $attributes ) );
|
||||
}
|
||||
@@ -175,8 +251,12 @@ class Form
|
||||
* @desc adds a field for entering the email address
|
||||
* @param $attributes
|
||||
*/
|
||||
public static function addInputTypeEmail( $attributes )
|
||||
public static function addInputTypeEmail( $attributes, $div = false )
|
||||
{
|
||||
if($div)
|
||||
{
|
||||
self::setDiv( $div );
|
||||
}
|
||||
self::setElement( new TypeEmail() );
|
||||
self::assamble( self::getElement()->loadElement( $attributes ) );
|
||||
}
|
||||
@@ -185,8 +265,12 @@ class Form
|
||||
* @desc adds a field for entering a color-picker field
|
||||
* @param $attributes
|
||||
*/
|
||||
public static function addInputTypeColor( $attributes )
|
||||
public static function addInputTypeColor( $attributes, $div = false )
|
||||
{
|
||||
if($div)
|
||||
{
|
||||
self::setDiv( $div );
|
||||
}
|
||||
self::setElement( new TypeColor() );
|
||||
self::assamble( self::getElement()->loadElement( $attributes ) );
|
||||
}
|
||||
@@ -195,8 +279,12 @@ class Form
|
||||
* @desc adds a field for entering a date and time field
|
||||
* @param $attributes
|
||||
*/
|
||||
public static function addInputTypeDatetime( $attributes )
|
||||
public static function addInputTypeDatetime( $attributes, $div = false )
|
||||
{
|
||||
if($div)
|
||||
{
|
||||
self::setDiv( $div );
|
||||
}
|
||||
self::setElement( new TypeDatetime() );
|
||||
self::assamble( self::getElement()->loadElement( $attributes ) );
|
||||
}
|
||||
@@ -205,8 +293,12 @@ class Form
|
||||
* @desc adds a file upload field to the form
|
||||
* @param $attributes
|
||||
*/
|
||||
public static function addTypeFileUpload( $attributes )
|
||||
public static function addTypeFileUpload( $attributes, $div = false )
|
||||
{
|
||||
if($div)
|
||||
{
|
||||
self::setDiv( $div );
|
||||
}
|
||||
self::setElement( new TypeFileUpload() );
|
||||
self::assamble( self::getElement()->loadElement( $attributes ) );
|
||||
}
|
||||
@@ -215,8 +307,12 @@ class Form
|
||||
* @desc adds a hidden field to the form
|
||||
* @param $attributes
|
||||
*/
|
||||
public static function addTypeHidden( $attributes )
|
||||
public static function addTypeHidden( $attributes, $div = false )
|
||||
{
|
||||
if($div)
|
||||
{
|
||||
self::setDiv( $div );
|
||||
}
|
||||
self::setElement( new TypeHidden() );
|
||||
self::assamble( self::getElement()->loadElement( $attributes ) );
|
||||
}
|
||||
@@ -225,8 +321,12 @@ class Form
|
||||
* @desc adds an image as the submit button to the form
|
||||
* @param $attrbutes
|
||||
*/
|
||||
public static function addTypeImageSubmit( $attrbutes )
|
||||
public static function addTypeImageSubmit( $attrbutes, $div = false )
|
||||
{
|
||||
if($div)
|
||||
{
|
||||
self::setDiv( $div );
|
||||
}
|
||||
self::setElement( new TypeImageSubmit() );
|
||||
self::assamble( self::getElement()->loadElement( $attrbutes ) );
|
||||
}
|
||||
@@ -235,8 +335,12 @@ class Form
|
||||
* @desc adds a field for entering a number
|
||||
* @param $attributes
|
||||
*/
|
||||
public static function addTypeNumber( $attributes )
|
||||
public static function addTypeNumber( $attributes, $div = false )
|
||||
{
|
||||
if($div)
|
||||
{
|
||||
self::setDiv( $div );
|
||||
}
|
||||
self::setElement( new TypeNumber() );
|
||||
self::assamble( self::getElement()->loadElement( $attributes ) );
|
||||
}
|
||||
@@ -246,8 +350,12 @@ class Form
|
||||
* Default range is from 0 to 100, to the form
|
||||
* @param $attributes
|
||||
*/
|
||||
public static function addTypeRange( $attributes )
|
||||
public static function addTypeRange( $attributes, $div = false )
|
||||
{
|
||||
if($div)
|
||||
{
|
||||
self::setDiv( $div );
|
||||
}
|
||||
self::setElement( new TypeRange() );
|
||||
self::assamble( self::getElement()->loadElement( $attributes ) );
|
||||
}
|
||||
@@ -256,8 +364,12 @@ class Form
|
||||
* @desc adds a reset button (resets all form values to default values), to the form
|
||||
* @param $attributes
|
||||
*/
|
||||
public static function addTypeReset( $attributes )
|
||||
public static function addTypeReset( $attributes, $div = false )
|
||||
{
|
||||
if($div)
|
||||
{
|
||||
self::setDiv( $div );
|
||||
}
|
||||
self::setElement( new TypeReset() );
|
||||
self::assamble( self::getElement()->loadElement( $attributes ) );
|
||||
}
|
||||
@@ -266,8 +378,12 @@ class Form
|
||||
* @desc adds a text field for entering a search string to the form
|
||||
* @param $attributes
|
||||
*/
|
||||
public static function addTypeSearch( $attributes )
|
||||
public static function addTypeSearch( $attributes, $div = false )
|
||||
{
|
||||
if($div)
|
||||
{
|
||||
self::setDiv( $div );
|
||||
}
|
||||
self::setElement( new TypeSearch() );
|
||||
self::assamble( self::getElement()->loadElement( $attributes ) );
|
||||
}
|
||||
@@ -276,8 +392,12 @@ class Form
|
||||
* @desc adds a field for entering a telefon number
|
||||
* @param $attributes
|
||||
*/
|
||||
public static function addTypeTelefon( $attributes )
|
||||
public static function addTypeTelefon( $attributes, $div = false )
|
||||
{
|
||||
if($div)
|
||||
{
|
||||
self::setDiv( $div );
|
||||
}
|
||||
self::setElement( new TypeTelefon() );
|
||||
self::assamble( self::getElement()->loadElement( $attributes ) );
|
||||
}
|
||||
@@ -286,8 +406,12 @@ class Form
|
||||
* @desc adds a field for entering a URL to the form
|
||||
* @param $attributes
|
||||
*/
|
||||
public static function addTypeUrl( $attributes )
|
||||
public static function addTypeUrl( $attributes, $div = false )
|
||||
{
|
||||
if($div)
|
||||
{
|
||||
self::setDiv( $div );
|
||||
}
|
||||
self::setElement( new TypeUrl() );
|
||||
self::assamble( self::getElement()->loadElement( $attributes ) );
|
||||
}
|
||||
@@ -297,13 +421,32 @@ class Form
|
||||
* an option field has been added
|
||||
* @param $attributes
|
||||
*/
|
||||
public static function addSelect( $attributes )
|
||||
public static function addSelect( $attributes, $div = false )
|
||||
{
|
||||
if($div!=false)
|
||||
{
|
||||
self::setDiv( $div );
|
||||
}
|
||||
self::setElement( new TypeSelect() );
|
||||
self::assamble( self::displaySelect( self::getElement()->loadElement( $attributes ) ) );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc adds a form element as button to the form
|
||||
* @param $attributes
|
||||
* @param bool $div
|
||||
*/
|
||||
public static function addTypeButton( $attributes, $div = false )
|
||||
{
|
||||
if($div!=false)
|
||||
{
|
||||
self::setDiv( $div );
|
||||
}
|
||||
self::setElement( new TypeButton() );
|
||||
self::assamble( self::getElement()->loadElement( $attributes ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc adds an option field to the form, should be used upfront to the select field
|
||||
* @param $attributes
|
||||
@@ -314,4 +457,17 @@ class Form
|
||||
self::assambleOptions( self::getElement()->loadElement( $attributes ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc adds a label to the form element
|
||||
* @param $attributes
|
||||
*/
|
||||
public static function addTypeLabel( $attributes, $div = false )
|
||||
{
|
||||
if($div!=false)
|
||||
{
|
||||
self::setDiv( $div );
|
||||
}
|
||||
self::setElement( new TypeLabel() );
|
||||
self::assamble( self::getElement()->loadElement( $attributes ) );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user