Hawk - PHP documentation
  • Namespace
  • Class
  • Tree

Namespaces

  • Hawk
    • View
      • Plugins

Classes

  • App
  • ButtonInput
  • Cache
  • CheckboxInput
  • ColorInput
  • Conf
  • Controller
  • Crypto
  • DatabaseSessionHandler
  • DatetimeInput
  • DB
  • DBExample
  • DeleteInput
  • Dialogbox
  • EmailInput
  • ErrorHandler
  • Event
  • FileInput
  • FileSystem
  • FloatInput
  • Form
  • FormFieldset
  • FormInput
  • GenericModel
  • GifImage
  • HawkApi
  • HawkUpdater
  • HiddenInput
  • HtmlInput
  • HTTPRequest
  • Icon
  • Image
  • IntegerInput
  • ItemList
  • ItemListField
  • JpegImage
  • Lang
  • Language
  • LeftSidebarTab
  • Less
  • Logger
  • Mail
  • MenuItem
  • Model
  • NoSidebarTab
  • NumberInput
  • ObjectInput
  • Option
  • Panel
  • PasswordInput
  • Permission
  • Plugin
  • PluginInstaller
  • PngImage
  • ProfileQuestion
  • ProfileQuestionValue
  • RadioInput
  • Request
  • Response
  • RightSidebarTab
  • Role
  • RolePermission
  • Route
  • Router
  • SelectInput
  • Session
  • Singleton
  • SubmitInput
  • Tabs
  • TextareaInput
  • TextInput
  • Theme
  • TimeInput
  • Upload
  • User
  • View
  • ViewPlugin
  • Widget
  • WysiwygInput

Traits

  • Utils

Exceptions

  • AppStopException
  • DBExampleException
  • DBException
  • FileSystemException
  • HawkApiException
  • ImageException
  • MailException
  • UploadException
  • ViewException

Class Form

This class is used to generate, display and treat forms.

Hawk\Form uses Hawk\Utils
Namespace: Hawk
Package: Form
Located at Form/Form.php

Methods summary

public
# __construct( array $param = array() )

Constructor

Constructor

Parameters

$param
The form parameters
public static Hawk\Form
# getInstance( string $id )

Get a form instance

Get a form instance

Parameters

$id
the form id to get

Returns

Hawk\Form
The form instance
public
# setParam( mixed $param, mixed $value = null )

Set form parameters

Set form parameters

Parameters

$param

The parameter name to set. If this parameter is an array, then this function will set all parameters defined by the keys of this array with the associated value

$value
The value to apply to the parameter
public
# reload( )

Reload the form data

Reload the form data

public
# setData( array $data, string $prefix = '' )

Set the values for field

Set the values for field

Parameters

$data

The data to set, where the keys are the names of the field, and the array values, the values to affect

$prefix

A prefix to apply on the field name, if it is defined as an array (used internally to the class)

public mixed
# getData( string $name = null )

Get data of the form

Get data of the form

Parameters

$name

If set, the function will return the value of the field, else it will return an array containing all field values

Returns

mixed

If $name is set, the function will return the value of the field, else it will return an array containing all field values

public
# addFieldset( Hawk\FormFieldset $fieldset )

Add a fieldset to the form

Add a fieldset to the form

Parameters

$fieldset
The fieldset to add to the form
public
# addInput( Hawk\FormInput $input, string $fieldset = '' )

Add an input to the form

Add an input to the form

Parameters

$input
The input to insert in the form
$fieldset

(optionnal) The fieldset where to insert the input. If not set, the input will be just included in $form->inputs, out of any fieldset

public mixed
# submitted( )

Defines if the form has been submitted, and if so, return the action to perform (submitted or delete)

Defines if the form has been submitted, and if so, return the action to perform (submitted or delete)

Returns

mixed

If the form is not submitted, this function will return FALSE. Else, the function will return 'register' or 'delete', depending on the user action

public string
# wrap( string $content )

This method is used when you define your own template for displaying the form content. It will wrap the form content with the

<

form> tag, and all the parameters defined for this form

This method is used when you define your own template for displaying the form content. It will wrap the form content with the

<

form> tag, and all the parameters defined for this form

Parameters

$content
The form content to wrap

Returns

string
The HTML result
public string
# __toString( )

Display the form (alias of display method)

Display the form (alias of display method)

Returns

string
The HTML result of form displaying
public string
# display( )

Display the form

Display the form

Returns

string
The HTML result of form displaying
public boolean
# check( boolean $exit = Hawk\Form::EXIT_JSON )

Check if the submitted values are correct

Check if the submitted values are correct

Parameters

$exit

If set to true and if the data is not valid, this function will output the validation result on HTTP response

Returns

boolean
true if the data is valid, false else.
public mixed
# register( boolean $exit = Hawk\Form::EXIT_JSON, string $success = "", string $error = "" )

Register the submitted data in the database

Register the submitted data in the database

Parameters

$exit
If set to true, the script will output after function execution, not depending on the result
$success
Defines the message to output if the action has been well executed
$error
Defines the message to output if an error occured

Returns

mixed
The id of the created or updated element in the database
public mixed
# delete( boolean $exit = Hawk\Form::EXIT_JSON, string $success = "", string $error = "" )

Delete the element from the database

Delete the element from the database

Parameters

$exit
If set to true, the script will output after function execution, not depending on the result
$success
Defines the message to output if the action has been well executed
$error
Defines the message to output if an error occured

Returns

mixed
The id of the deleted object
public
# error( string $name, string $error )

Add an error on a field

Add an error on a field

Parameters

$name
The name of the input to apply the error
$error
The error message to apply
public
# addReturn( string $name, string $message = "" )

Add data to return to the client. To add several returns in on function call, define the first parameter as an associative array

Add data to return to the client. To add several returns in on function call, define the first parameter as an associative array

Parameters

$name
The name of the data to return
$message
The value to apply
public array
# response( string $status, string $message = '' )

Return the response of the form (generally when submitted), and set the Response HTTP code corresponding to the response, and the response type as JSON

Return the response of the form (generally when submitted), and set the Response HTTP code corresponding to the response, and the response type as JSON

Parameters

$status
The status to output. You can use the class constants STATUS_SUCCESS, STATUS_CHECK_ERROR or STATUS_ERROR
$message
The message to output. If not set, the default message corresponding to the status will be output

Returns

array
The response result, that will be displayed as json when the script ends
public mixed
# treat( boolean $exit = Hawk\Form::EXIT_JSON )

Make a generic treatment that detect the action to execute, check the form if necessary, and execute the action

Make a generic treatment that detect the action to execute, check the form if necessary, and execute the action

Parameters

$exit
If true, exit the script after function execution

Returns

mixed
The id of the treated element

Methods used from Hawk\Utils

debug(), getSerializedVersion(), map()

Constants summary

boolean NO_EXIT
# false
boolean EXIT_JSON
# true
string VIEWS_DIR
# 'form/'
string STATUS_SUCCESS
# 'success'
string STATUS_ERROR
# 'error'
string STATUS_CHECK_ERROR
# 'check-error'
integer HTTP_CODE_SUCCESS
# 200
integer HTTP_CODE_CHECK_ERROR
# 412
integer HTTP_CODE_ERROR
# 424
string ACTION_REGISTER
# 'register'
string ACTION_DELETE
# 'delete'
string DEFAULT_MODEL
# "GenericModel"

Properties summary

public string $method

The submit method (Default : POST)

The submit method (Default : POST)

# 'post'
public string $name

The form name

The form name

# ''
public string $id

The form id

The form id

# ''
public string $model

The model class used for display and database treatment

The model class used for display and database treatment

# Hawk\Form::DEFAULT_MODEL
public Object $object

The object treated by the form

The object treated by the form

#
public string $labelWidth

The width of the input labels (if defined, overrides the default label width defined in the theme)

The width of the input labels (if defined, overrides the default label width defined in the theme)

# ''
public string $status

The submission status. This variable can be used if you want to know the treatment status before executing other instructions

The submission status. This variable can be used if you want to know the treatment status before executing other instructions

# null
public integer $columns

The number of columns to display the form. Each fieldset will be displayed on a column. For example, if you define 6 fieldsets in your form, and select 3 for this property, the form will be displayed on 2 lines, with 3 fieldsets by line.

The number of columns to display the form. Each fieldset will be displayed on a column. For example, if you define 6 fieldsets in your form, and select 3 for this property, the form will be displayed on 2 lines, with 3 fieldsets by line.

# 1
public string $class

This property can be set if you want to apply a css class to the form

This property can be set if you want to apply a css class to the form

# ''
public boolean $autocomplete

Defines if the form can autocompleted (Default true)

Defines if the form can autocompleted (Default true)

# true
public array $fieldsets

The form fieldsets

The form fieldsets

# array()
public array $inputs

The form inputs

The form inputs

# array()
public boolean $upload

Defines if the form do an AJAX uplaod

Defines if the form do an AJAX uplaod

# false
public boolean $nomessage

If set to true, no return message will be displayed when the form is submitted

If set to true, no return message will be displayed when the form is submitted

# false
public string $action

Defines the form action. Default value is the current URL

Defines the form action. Default value is the current URL

# ''
public array $returns

The data returned by the form

The data returned by the form

# array()
public array $errors

The form errors

The form errors

# array()
public array $reference

The reference to get the object in the database and update it. This property must be displayed as : array( 'field' => 'value', 'field2' => 'value2' )

The reference to get the object in the database and update it. This property must be displayed as : array( 'field' => 'value', 'field2' => 'value2' )

# array()
Hawk - PHP documentation API documentation generated by ApiGen