Jelix 1.6.37

jFormsBase
in package

base class of all form classes generated by the jform compiler

Tags
subpackage

forms

Table of Contents

SECURITY_CSRF  = 1
SECURITY_LOW  = 0
$securityLevel  : mixed
$builders  : bool
content list of available form builder
$container  : jFormsDataContainer
the data container
$controls  : array<string|int, jFormsControl>
List of all form controls
$hiddens  : array<string|int, jFormsControlHidden>
List of hidden controls
$htmleditors  : array<string|int, jFormsControlHtmlEditor>
List of htmleditorcontrols
$reset  : jFormsControlReset
Reset button
$rootControls  : array<string|int, jFormsControl>
List of top controls
$sel  : string
the form selector
$submits  : array<string|int, jFormsControlSubmit>
List of submit buttons
$uploads  : array<string|int, jFormsControlUpload>
List of uploads controls
$wikieditors  : array<string|int, jFormsControlWikiEditor>
List of wikieditorcontrols
__construct()  : mixed
addChildControl()  : mixed
declare a child control to the form. The given control should be a child of an other control
addControl()  : mixed
add a control to the form
addControlBefore()  : mixed
add a control to the form, before the specified control
check()  : bool
check validity of all data form
createNewToken()  : string
generate a new token for security against CSRF a builder should call it and create for example an hidden input so jForms could verify it after the submit.
deactivate()  : mixed
deactivate (or reactivate) a control When a control is deactivated, it is not displayes anymore in the output form
getAllData()  : array<string|int, mixed>
getBuilder()  : BuilderBase|jFormsBuilderBase
getContainer()  : jFormsDataContainer
getControl()  : jFormsControl
getControls()  : array<string|int, jFormsControl>
getData()  : string|array<string|int, mixed>
getErrors()  : array<string|int, mixed>
return list of errors found during the check
getHiddens()  : array<string|int, jFormsControlHidden>
getHtmlEditors()  : array<string|int, jFormsControlHtmlEditor>
getModifiedControls()  : array<string|int, mixed>
returns the old values of the controls which have been modified since the call of the method initModifiedControlsList()
getReset()  : jFormsControlReset
getRootControls()  : array<string|int, jFormsControl>
getSelector()  : string
getSubmits()  : array<string|int, jFormsControlSubmit>
getUploads()  : array<string|int, jFormsControlUpload>
getWikiEditors()  : array<string|int, jFormsControlWikiEditor>
hasData()  : bool
hasUpload()  : bool
id()  : string
initControlFromDao()  : mixed
set data from a DAO, in a control
initFromDao()  : jDaoRecordBase
set form data from a DAO
initFromRequest()  : mixed
set form data from request parameters
initModifiedControlsList()  : mixed
call this method after initialization of the form, in order to track modified controls
isActivated()  : bool
check if a control is activated
isReadOnly()  : bool
check if a control is readonly
prepareDaoFromControls()  : array<string|int, mixed>
prepare a dao with values of all controls
prepareObjectFromControls()  : mixed
prepare an object with values of all controls
removeControl()  : mixed
saveAllFiles()  : mixed
save all uploaded file in the given directory
saveControlToDao()  : mixed
save data of a control using a dao.
saveFile()  : bool
save an uploaded file in the given directory. the given control must be an upload control of course.
saveToDao()  : mixed
save data using a dao.
setData()  : mixed
setErrorOn()  : mixed
set an error message on a specific field
setReadOnly()  : mixed
set a control readonly or not

Constants

Properties

$builders

content list of available form builder

protected bool $builders = array()

Methods

__construct()

public __construct(string $sel, jFormsDataContainer $container[, bool $reset = false ]) : mixed
Parameters
$sel : string

the form selector

$container : jFormsDataContainer

the data container

$reset : bool = false

says if the data should be reset

Return values
mixed

addChildControl()

declare a child control to the form. The given control should be a child of an other control

public addChildControl(jFormsControl $control) : mixed
Parameters
$control : jFormsControl
Return values
mixed

addControlBefore()

add a control to the form, before the specified control

public addControlBefore(jFormsControl $control, string $ref) : mixed
Parameters
$control : jFormsControl

the control to add

$ref : string

The ref of the control the new control should be inserted before

Tags
since
1.1
Return values
mixed

check()

check validity of all data form

public check() : bool
Return values
bool

true if all is ok

createNewToken()

generate a new token for security against CSRF a builder should call it and create for example an hidden input so jForms could verify it after the submit.

public createNewToken() : string
Tags
since
1.1.2
Return values
string

the token

deactivate()

deactivate (or reactivate) a control When a control is deactivated, it is not displayes anymore in the output form

public deactivate(string $name[, bool $deactivation = true ]) : mixed
Parameters
$name : string

the name of the control

$deactivation : bool = true

TRUE to deactivate, or FALSE to reactivate

Tags
throws
jExceptionForms
Return values
mixed

getAllData()

public getAllData() : array<string|int, mixed>
Return values
array<string|int, mixed>

form data

getData()

public getData(string $name) : string|array<string|int, mixed>
Parameters
$name : string

the name of the control/data

Return values
string|array<string|int, mixed>

the data value

getErrors()

return list of errors found during the check

public getErrors() : array<string|int, mixed>
Tags
see
jFormsBase::check()
Return values
array<string|int, mixed>

getModifiedControls()

returns the old values of the controls which have been modified since the call of the method initModifiedControlsList()

public getModifiedControls() : array<string|int, mixed>
Tags
since
1.1
Return values
array<string|int, mixed>

key=control id, value=old value

hasData()

public hasData(string $name) : bool
Parameters
$name : string

the name of the control/data

Return values
bool

true if there is a data with this name

initControlFromDao()

set data from a DAO, in a control

public initControlFromDao(string $name, string $daoSelector[, mixed $primaryKey = null ][, mixed $primaryKeyNames = null ][, string $dbProfile = '' ]) : mixed

The control must be a container like checkboxes or listbox with multiple attribute. The form should contain a formId

The Dao should map to an "association table" : its primary key should be composed by the primary key stored in the formId (or the given primarykey) + the field which will contain one of the values of the control. If this order is not the same as defined into the dao, you should provide the list of property names which corresponds to the primary key in this order : properties for the formId, followed by the property which contains the value.

Parameters
$name : string

the name of the control

$daoSelector : string

the selector of a dao file

$primaryKey : mixed = null

the primary key if the form have no id. (optional)

$primaryKeyNames : mixed = null

list of field corresponding to primary keys (optional)

$dbProfile : string = ''

the jDb profile to use with the dao

Tags
throws
jExceptionForms
see
jDao
Return values
mixed

initFromDao()

set form data from a DAO

public initFromDao(string|jDaoRecordBase $daoSelector[, string $key = null ][, string $dbProfile = '' ]) : jDaoRecordBase
Parameters
$daoSelector : string|jDaoRecordBase

the selector of a dao file or a DAO record

$key : string = null

the primary key for the dao. if null, takes the form ID as primary key. Only needed when string dao selector given.

$dbProfile : string = ''

the jDb profile to use with the dao

Tags
throws
jExceptionForms
see
jDao
Return values
jDaoRecordBase

initFromRequest()

set form data from request parameters

public initFromRequest() : mixed
Return values
mixed

initModifiedControlsList()

call this method after initialization of the form, in order to track modified controls

public initModifiedControlsList() : mixed
Tags
since
1.1
Return values
mixed

isActivated()

check if a control is activated

public isActivated(string $name) : bool
Parameters
$name : string

the control name

Return values
bool

true if it is activated

isReadOnly()

check if a control is readonly

public isReadOnly(mixed $name) : bool
Parameters
$name : mixed
Return values
bool

true if it is readonly

prepareDaoFromControls()

prepare a dao with values of all controls

public prepareDaoFromControls(string $daoSelector[, string $key = null ][, string $dbProfile = '' ]) : array<string|int, mixed>
Parameters
$daoSelector : string

the selector of a dao file

$key : string = null

the primary key for the dao. if null, takes the form ID as primary key

$dbProfile : string = ''

the jDb profile to use with the dao

Tags
see
jDao
Return values
array<string|int, mixed>

return three vars : $daorec, $dao, $toInsert which have to be extracted

prepareObjectFromControls()

prepare an object with values of all controls

public prepareObjectFromControls(object $object[, array<string|int, mixed> $properties = null ]) : mixed
Parameters
$object : object

the object to fill

$properties : array<string|int, mixed> = null

array of 'propertyname'=>array('required'=>true/false, 'defaultValue'=>$value, 'unifiedType'=>$datatype) values of datatype = same as jdb unified types

Return values
mixed

removeControl()

public removeControl(mixed $name) : mixed
Parameters
$name : mixed
Return values
mixed

saveAllFiles()

save all uploaded file in the given directory

public saveAllFiles([string $path = '' ]) : mixed
Parameters
$path : string = ''

path of the directory where to store the file. If it is not given, it will be stored under the var/uploads/modulename~formname/ directory

Return values
mixed

saveControlToDao()

save data of a control using a dao.

public saveControlToDao(string $controlName, string $daoSelector[, mixed $primaryKey = null ][, mixed $primaryKeyNames = null ][, string $dbProfile = '' ]) : mixed

The control must be a container like checkboxes or listbox with multiple attribute. If the form contain a new record (no formId), you should call saveToDao before in order to get a new id (the primary key of the new record), or you should get a new id by an other way. then you must pass this primary key in the third argument. If the form has already a formId, then it will be used as a primary key, unless you give one in the third argument.

The Dao should map to an "association table" : its primary key should be the primary key stored in the formId + the field which will contain one of the values of the control. If this order is not the same as defined into the dao, you should provide the list of property names which corresponds to the primary key in this order : properties for the formId, followed by the property which contains the value. All existing records which have the formid in their keys are deleted before to insert new values.

Parameters
$controlName : string

the name of the control

$daoSelector : string

the selector of a dao file

$primaryKey : mixed = null

the primary key if the form have no id. (optional)

$primaryKeyNames : mixed = null

list of field corresponding to primary keys (optional)

$dbProfile : string = ''

the jDb profile to use with the dao

Tags
throws
jExceptionForms
see
jDao
Return values
mixed

saveFile()

save an uploaded file in the given directory. the given control must be an upload control of course.

public saveFile(string $controlName[, string $path = '' ][, string $alternateName = '' ]) : bool
Parameters
$controlName : string

the name of the upload control

$path : string = ''

path of the directory where to store the file. If it is not given, it will be stored under the var/uploads/modulename~formname/ directory

$alternateName : string = ''

a new name for the file. If it is not given, the file while be stored with the original name

Tags
throws
jExceptionForms
Return values
bool

true if the file has been saved correctly

saveToDao()

save data using a dao.

public saveToDao(string $daoSelector[, string $key = null ][, string $dbProfile = '' ]) : mixed

it call insert or update depending the value of the formId stored in the container

Parameters
$daoSelector : string

the selector of a dao file

$key : string = null

the primary key for the dao. if null, takes the form ID as primary key

$dbProfile : string = ''

the jDb profile to use with the dao

Tags
see
jDao
Return values
mixed

the primary key of the new record in a case of inserting

setData()

public setData(string $name, string|array<string|int, string> $value) : mixed
Parameters
$name : string

the name of the control/data

$value : string|array<string|int, string>

the data value

Tags
throws
jExceptionForms
Return values
mixed

setErrorOn()

set an error message on a specific field

public setErrorOn(string $field, string $mesg) : mixed
Parameters
$field : string

the field name

$mesg : string

the error message string

Return values
mixed

setReadOnly()

set a control readonly or not

public setReadOnly( $name[, bool $r = true ]) : mixed
Parameters
$name :
$r : bool = true

true if you want read only

Tags
throws
jExceptionForms
Return values
mixed

Search results