Form Library



( ZN > 1.0.0 )

By bringing the form objects into the class form, it is aimed to use it in the controller as well as the appearance. With object chaining, desired property value pairs can be easily added. Especially because it can work directly with the database, it provides great convenience and advantage compared to the standard form usage. In addition, DB :: , Validation :: and Permission :: is integrated with the library works.

 

 

# Methods


String open ( String $ name = NULL , Array $ attr = [] )
String close ( Void )
String text ( String $ name = NULL , String $ value = NULL , Array $ attr = [] )
String password ( String $ name = NULL , String $ value = NULL , Array $ attr = [] )
String textarea ( String $ name = NULL , String $ value = NULL , Array $ attr = [] )
this postback ( Bool $ postback = true , String $ type = 'post' )
this validate ( Mixed ... $ rules )
String submit ( String $ name = NULL , String $ value = NULL , Array $ attr = [] )
String reset ( String $ name = NULL , String $ value = NULL , Array $ attr = [] )
String button ( String $ name = NULL , String $ value = NULL , Array $ attr = [] )
String radio ( String $ name = NULL , String $ value = NULL , Array $ attr = [] )
String checkbox ( String $ name = NULL , String $ value = NULL , Array $ attr = [] )
String select ( String $ name = NULL , Array $ options , String $ selectedKey = NULL , Array $ attr = [] )
String multiselect ( String $ name = NULL , Array $ options , String $ selectedKey = NULL , Array $ attr = [] )
String net ( String $ name = NULL , Boolean $ Multiupload = false , Array $ attr = [] )

 

 

# HTML5 Objects


Since all HTML5  objects use the form objects in the same structure, you can use the name of the form objects that come with HTML5 instead of html5InputName below . 

String html5InputName ( String $ name = NULL , String $ value = NULL , Array $ attr = [] )

 

 

# Features


All HTMLproperties that apply to all form objects can be used with a method.

Form::id('example')->style('red:color')-> - - -

The methods id () , style () used above are used to specify the constructs that make up the property value pair of the input object. This usage is common to all form objects. Each Form :: Object can provide parameter usage with these optional methods besides its own parameters. If the property is composed of multiple words and a hyphen (-) between them , this property is used in the form camelCase ie exampleElement () .

Parameters
String $ value NULL If it's your value.
return this  
uses
echo Form::required()->placeholder('Name Please')->id('name')->text('name');
Tire Use with Brackets

If your form properties are separated by data - validation - you should write in the camelCase standard.

Form::dataValidation('required')->myId(1)->textarea('name', 'Value');
<textarea data-validation="required" my-id="1" name="name">Value</textarea>

 

 

# Open ( ZN> 1.0.0 )


It is against the use of html .<form>

Parameters
String $ name NULL Object name.
Array  $ attr [] Features.
return String  
Use of
echo Form::action('home')->method('get')->open('example-form');
<form name="example-form" method="get" action="https://www.example.xxx/home">
Optional Methods
this enctype ( String $ type )
this where ( String $ column , Scalar $ value , String $ logical = 'and' )
this query ( String $ query )
this process ( String $ process )

 

# Enctype ( ZN> 3.0.1 )


Used to set the enctype value of the form object. This value should be used especially for file upload operations.

Parameters

String $ type

NULL

Kind.

multipart - application - text

return

this

Use of
echo Form::enctype('multipart')->open('upload-form');

 

# CSRF ( ZN > 4.3.6 )


To prevent CSRF attacks token creates the data.

Parameters
void
return this
Use of
echo Form::csrf()->open('form');

 

# Where ( ZN> 5.4.2 )


It is used to link the form to the table record. DB :: where (). With this method, you can directly connect the desired table to the corresponding record according to the desired condition. As table nameform of objects name value is used.

Parameters
String $ column NULL Column name.
String $ value NULL Column value.
String $ logical and and - or Conjunctions.
return this
Use of
echo Form::where('id', URI::get('id'))->open('accounts');
Form Objects

After the table definition, other form objects automatically retrieve the value from the record. The exception is the use of checkbox, radio buttons and select object.

Radio Buton

In order for the radio buttons to be selected, the given value must match the incoming value.

Male  /: @Form::radio('gender', 1):
Female/: @Form::radio('gender', 2):

In the above definition, if the value of the gender column matches the value, that button becomes selected.

Checkbox Button

The checkbox must match the value in the incoming record so that the buttons can be selected. However, checkbox values ​​are usually stored in json format like [1,2,5,10]. Json analysis is performed automatically and the corresponding buttons are selected.

@Form::checkbox('red'  , 1):
@Form::checkbox('green', 2):
@Form::checkbox('blue' , 5):
@Form::checkbox('brown', 20):

If any of the above buttons match, those buttons become selected.

Select List

For the selective entry of the Select object, its values ​​must be defined.

Gender/@Form::select('gender', [1 => 'Male', 2 => 'Female']):

In the above definition, if the value of the gender column matches the value, that value becomes selected.

 

# Query ( ZN> 5.4.2 )


If you want to link complex questions to a table, you can use this method. This is the same as using DB :: query () .

Parameters
String $ query NULL Query.
return this
Use of
echo Form::query(DB::string()->where('id', URI::get('id'))->accounts())->open('accounts');

 

# Process ( ZN> 5.4.2 )


It is for you to automatically update and add form.

Parameters
String $ process NULL insert - update Operation type.
return this
Use of
@Form::where('id', 1)->process('update')->open('users'):
@Form::postback()->validate('required', 'xss')->text('name'):
@Form::postback()->validate('email', 'required')->text('email'):
@Form::select('gender', [1 => 'Male', 2 => 'Female']):
@Form::validate('required')->textarea('about'):
@Form::submit('submit', 'Submit'):
@Form::close():
@Form::validateErrorMessage():
Catching the Validation Error Message

The following two methods are used to catch the validation error that occurs after Submit .

Form::validateErrorMessage()
Form::validateErrorArray()
Warning: These methods must use the process () method in order to be able to generate values .

 

 

# Close ( ZN> 1.0.0 )


It is against the use of html .</form>

Parameters
void
return String
uses
echo Form::close();
< / form >

 

 

# Text ( ZN > 1.0.0 )


It is against the use of html .<form input="text">

Parameters
String $ name NULL Object name.
String $ value NULL Value.
Array $ attr [] Features.
return  String
uses
echo Form::id('example-text')
         ->maxlength(10)
         ->text('textBox', 'Welcome!');
< input type = "text" name = "textBox" value = "Welcome!" id = "example-text" maxlength = "10" >

 

 

# Password ( ZN> 1.0.0 )


It is against the use of html .<form input="password">

Parameters
String $ name NULL Object name.
String $ value NULL Value.
Array $ attr [] Features.
return  String
uses
echo Form::password('password', '  *', ['maxlength' => 10]);
< input type = "password" maxlength = "10" name = "password" value = " *" > 

 

 

# Textarea ( ZN > 1.0.0 )


It is against the use of html .<textarea>

Parameters
String $ name NULL Object name.
String $ value NULL Value.
Array $ attr [] Features.
return  String
uses
echo Form::cols(50)->rows(5)->textarea('address', 'Address');
< textarea cols = "50" rows = "5" name = "address" > Address < / textarea >

 

 

# Postback ( ZN> 4.0.0 )


It is used to maintain the last value of the form elements when the form is submitted.

Parameters
Bool $ postback true Are values ​​preserved? false the values ​​will not be preserved.
String $ type hide post - get - request If the method type of the form is specified, this value is based on the form's current method type.
return this
uses
echo Form::postback()->text('name');

 

 

# Validate ( ZN> 5.4.2 )


Validation :: rules ()method. It allows you to use rules differently with the form object.

Parameters
Mixed ... $ args NULL Rules line.
return this
uses
echo Form::validate('required', 'xss', ['minchar' => 10])->text('name');
Nickname

Used to set how the return type of the form object will be displayed if the alias validation control fails.

echo Form::validate('required', 'xss', ['minchar' => 10])->alias('Name:')->text('name');
Rules Control

Rules sent over the Form object Controller at the foot Validation :: check ( $ submitName ) method.

File: Views / home / main.wizard.php
@Form::open():

@Form::postback()
      ->validate('email', 'required')
      ->alias('Email/:')
      ->text('email'):

@Form::submit('submit', 'Submit'):

@Form::close():

{{$error ?? NULL}}
File: Controllers / home.php
<?php namespace Project\Controllers;

use Validation, Post;

class Home extends Controller
{
    public function main(String $params = NULL)
    {
        if( ! Validation::check('submit') )
        {
            View::error(Validation::error('string'));
        }
    }
}

 

 

# Submit ( ZN> 1.0.0 )


Html < form input = "submit" > .

Parameters
String $ name NULL Object name.
String $ value NULL Value.
Array $ attr [] Features.
return  String
Examples
echo Form::submit('sendSubmit', 'Send');
< input type = "submit" name = "sendSubmit" value = "Send" >

 

 

# Reset ( ZN> 1.0.0 )


Html < form input = "reset" > .

Parameters
String $ name NULL Object name.
String $ value NULL Value.
Array $ attr [] Features.
return  String
Examples
echo Form::reset('clear', 'Clear');
< input type = "reset" name = "clear" value = "Clear" >

 

 

# Button ( ZN> 1.0.0 )


Html < form input = "submit" > .

Parameters
String $ name NULL Object name.
String $ value NULL Value.
Array $ attr [] Features.
return  String
Examples
echo Form::button('sendButton', 'Send');
< input type = "button" name = "sendButton" value = "Send" >

 

 

# Radio ( ZN> 1.0.0 )


Html < form input = "radio" > usage.

Parameters
String $ name NULL Object name.
String $ value NULL Value.
Array $ attr [] Features.
return  String
Examples
echo Form::checked()->radio('gender', 'Female');
echo Form::radio('gender', 'Male'); 
< Input type = "radio" name = "gender" value = "Female" checked = "checked" >
< input type = "radio" name = "gender" value = "Male" >

 

 

# Checkbox ( ZN> 1.0.0 )


It is against the use of Html < form input = "checkbox" > .

Parameters
String $ name NULL Object name.
String $ value NULL Value.
Array $ attr [] Features.
return  String
Examples
echo Form::checked()->checkbox('trueType', 'true');
echo Form::checkbox('trueType', 'false'); 
< Input type = "checkbox" name = "TrueType" value = "true" checked = "checked" >
< input type = "checkbox" name = "TrueType" value = "false" >

 

 

# Select / Multiselect ( ZN > 1.0.0 )


Html is the equivalent of using < select > .

Parameters
String $ name NULL Object name.
Array $ options [] Options.
String $ selectedKey NULL Selected key.
Array $ attr [] Features.
return  String
Optional Methods
this table ( String $ table )
this query ( String $ query )
this including ( Mixed $ data )
this excluding ( Mixed $ data )
this order ( String $ type = 'desc' , String $ flags = 'regular' )
this option ( Mixed $ key , String $ value = NULL )
uses
$options = [ '34' => 'Istanbul', '19' => 'Corum' ];

echo Form::select('cities', $options, '19');
< Select name = "cities" >
    < option value = "34"> Istanbul < / option >
    < option value = "19" selected = "selected" > Crum < / option >
< / select >

If you want to pull options from v.3.0.1 or later directly from the databasetable () orYou can use the query () methods.

echo Form::table('accounts')
         ->select('accountList', ['keyColumn' => 'valueColumn']);

If you want to define the default key value for the first element, you can use it as follows.

echo Form::table('accounts')->select('accountList',
[
//  'keyColumn'  => 'valueColumn'
    'id'         => 'name',
//  'defaultKey' => 'defaultValue'
    '0'          => 'Musteri seciniz'
]);

Or

$query = DB::string()->accounts();

echo Form::query($query)->select('accountList', ['id' => 'name']);

In v.3.1.0 version, you can choose whether or not you wantincluding ()  andYou can specify it using the excluding () methods.

including
echo Form::including([2, 3])
         ->select('cityList',
         [
             1 => 'Istanbul', 
             2 => 'Londra', 
             3 => 'Paris'
         ]); 

// output: Londra, Paris
excluding
echo Form::excluding([2, 3])
         ->select('cityList',
         [
             1 => 'Istanbul',
             2 => 'Londra',
             3 => 'Paris'
         ]); 

// output: İstanbul

 

 

# File ( ZN> 1.0.0 )


It is the equivalent of using Html < form input = "file" > .

Parameters
String $ name NULL Object name.
Bool $ multiple false Can you do a lot of file uploads? If this value is set to true, more than one file can be selected at the same time in the file selection window.
Array $ attr [] Features.
return  String
Examples
echo Form::file('upload');
< input type = "file" name = "upload" >
Multiple File Upload

If you want to make multiple uploads , it is possible to use as follows.

echo Form::file('upload', true);
< input type = "file" name = "upload []" multiple = "multiple" >