TwigForm

Form
in package

Form class to build form configurations and render them

Table of Contents

Properties

$defaultTwigForm  : mixed
$fieldIDs  : mixed
$formAction  : mixed
$formAttributes  : mixed
$formButtons  : mixed
$formDefinition  : mixed
$formEnctype  : mixed
$formID  : mixed
$formIdentifier  : mixed
$formMethod  : mixed
$formRows  : mixed
$formSubmit  : mixed
$hiddenFields  : mixed
$renderAttributes  : mixed
$selectedTemplate  : mixed
$templates  : mixed

Methods

__construct()  : mixed
constructor of Form element
__toString()  : string
Function to build and return JSON representation of the current form
addHiddenField()  : mixed
add a hidden field to the current form
addRenderAttribute()  : mixed
Add a render attribute / TwigVariable
addTwigTemplate()  : mixed
Add additional Twig templates for being rendered; is not meant to be used with instances of \macwinnie\TwigForm\Template
formGetIdent()  : string
function to gather the current form identifier
loadJSON()  : void
Load a Form by JSON description
renderForm()  : string
Function for final rendering the selected Template with the given form data
selectTemplate()  : void
Select another template to be rendered instead of `form`
setAction()  : mixed
function to set form action
setFormAttribute()  : mixed
set attributes used within main form element
setFormEnctype()  : mixed
set enctype for form
setFormID()  : mixed
set the form identifier
setMethod()  : mixed
set the form method
setSubmitAttribute()  : mixed
set attributes for regular submit input
transformTemplate()  : static
Basic transformation from Twig Template (analyzed, so instance of `macwinnie\TwigForm\Template`) to Form (of `static` class) object
addRow()  : mixed
add a row to the form
getFormCreate()  : array<string|int, mixed>
function to provide create part of form definition
getSubmit()  : mixed
get submit input data for string representation

Properties

$defaultTwigForm

private mixed $defaultTwigForm = 'twigform'

$fieldIDs

private mixed $fieldIDs = []

$formAction

private mixed $formAction = []

$formAttributes

private mixed $formAttributes = []

$formButtons

private mixed $formButtons = []

$formDefinition

private mixed $formDefinition = NULL

$formEnctype

private mixed $formEnctype = 'multipart/form-data'

$formID

private mixed $formID = NULL

$formIdentifier

private mixed $formIdentifier = 'form_data'

$formMethod

private mixed $formMethod = 'POST'

$formRows

private mixed $formRows = []

$formSubmit

private mixed $formSubmit = []

$hiddenFields

private mixed $hiddenFields = []

$renderAttributes

private mixed $renderAttributes = []

$selectedTemplate

private mixed $selectedTemplate = 'form'

$templates

private mixed $templates

Methods

__construct()

constructor of Form element

public __construct() : mixed

__toString()

Function to build and return JSON representation of the current form

public __toString() : string
Return values
string

JSON

addHiddenField()

add a hidden field to the current form

public addHiddenField(string $name[, string $value = '' ]) : mixed
Parameters
$name : string

identifier (name and id postfix) for the hidden field

$value : string = ''

value for the hidden field

addRenderAttribute()

Add a render attribute / TwigVariable

public addRenderAttribute(string $name, mixed $value) : mixed
Parameters
$name : string

name of the variable (top level only!)

$value : mixed

value / array / ... to be assigned for rendering

addTwigTemplate()

Add additional Twig templates for being rendered; is not meant to be used with instances of \macwinnie\TwigForm\Template

public addTwigTemplate(string $name, TemplateWrapper $template) : mixed
Parameters
$name : string

identifier of the new template

$template : TemplateWrapper

Twig template

formGetIdent()

function to gather the current form identifier

public formGetIdent() : string
Return values
string

form identifier

loadJSON()

Load a Form by JSON description

public loadJSON(string $json) : void
Parameters
$json : string

JSON representation of a form

Tags
throws
Exception

JSON not valid

renderForm()

Function for final rendering the selected Template with the given form data

public renderForm() : string
Return values
string

HTML content of the selected template with the form

selectTemplate()

Select another template to be rendered instead of `form`

public selectTemplate(string $name[, string $formIdentifier = 'form_data' ]) : void
Parameters
$name : string

name of template

$formIdentifier : string = 'form_data'

ident of the form_data parameter to be used

Tags
throws
Exception

Template not existent / loaded ...

setAction()

function to set form action

public setAction(string $dest[, string $type = 'url' ]) : mixed
Parameters
$dest : string

value to be set – according to $type

$type : string = 'url'

default is url ... may be route or action (Laravel specific)

setFormAttribute()

set attributes used within main form element

public setFormAttribute(string $name, string $value) : mixed
Parameters
$name : string

name of attribute

$value : string

value of attribute

setFormEnctype()

set enctype for form

public setFormEnctype(string $enctype[, bool $force = false ]) : mixed
Parameters
$enctype : string

see here for allowed values: https://wiki.selfhtml.org/wiki/HTML/Elemente/form

$force : bool = false

set enctype even if it's a value not allowed

setFormID()

set the form identifier

public setFormID(string $new[, bool $override = true ]) : mixed
Parameters
$new : string

new identifier for this form instance

$override : bool = true

attribute to define if formID should be overridden by $new; defaults to true

setMethod()

set the form method

public setMethod(string $method) : mixed

GET and POST are regular methods, specials are supported as defined in RFC 7231 https://datatracker.ietf.org/doc/html/rfc7231#section-4.3

Parameters
$method : string

method name

setSubmitAttribute()

set attributes for regular submit input

public setSubmitAttribute(string $key, string $value) : mixed
Parameters
$key : string

attribute to be set

$value : string

value to be set

transformTemplate()

Basic transformation from Twig Template (analyzed, so instance of `macwinnie\TwigForm\Template`) to Form (of `static` class) object

public static transformTemplate(Template $tpl[, string $id = NULL ]) : static
Parameters
$tpl : Template

template object to be transformed

$id : string = NULL

identifier / name of form

Return values
static

result of basic transformation

addRow()

add a row to the form

protected addRow(string $rowName) : mixed
Parameters
$rowName : string

row name has to be non-empty and not NULL.

getFormCreate()

function to provide create part of form definition

private getFormCreate() : array<string|int, mixed>
Return values
array<string|int, mixed>

create part of form definition

getSubmit()

get submit input data for string representation

private getSubmit() : mixed
Tags
throws
Exception

if submit is empty

Return values
mixed

form submit definition


        
On this page

Search results