Jet\Form_Field
Overview of constants
Field types
Constant / Type | Class | Purpose |
---|---|---|
Form_Field::TYPE_HIDDEN | Jet\Form_Field_Hidden | Hidden form field |
Form_Field::TYPE_INPUT | Jet\Form_Field_Input | General input field for any text |
Form_Field::TYPE_INT | Jet\Form_Field_Int | Integer |
Form_Field::TYPE_FLOAT | Jet\Form_Field_Float | Float |
Form_Field::TYPE_RANGE | Jet\Form_Field_Range | Selecting a number with the slider from the specified range |
Form_Field::TYPE_DATE | Jet\Form_Field_Date | Date |
Form_Field::TYPE_DATE_TIME | Jet\Form_Field_DateTime | Date and time |
Form_Field::TYPE_MONTH | Jet\Form_Field_Month | Selection of the month of the year |
Form_Field::TYPE_WEEK | Jet\Form_Field_Week | Choosing the week of the year |
Form_Field::TYPE_TIME | Jet\Form_Field_Time | Time |
Form_Field::TYPE_EMAIL | Jet\Form_Field_Email | E-mail address |
Form_Field::TYPE_TEL | Jet\Form_Field_Tel | Telephone number |
Form_Field::TYPE_URL | Jet\Form_Field_Url | URL |
Form_Field::TYPE_SEARCH | Jet\Form_Field_Search | Search field |
Form_Field::TYPE_COLOR | Jet\Form_Field_Color | Colour selection from the colour palette |
Form_Field::TYPE_SELECT | Jet\Form_Field_Select | Select one option from multiple options. |
Form_Field::TYPE_MULTI_SELECT | Jet\Form_Field_MultiSelect | Selecting multiple options from multiple options |
Form_Field::TYPE_CHECKBOX | Jet\Form_Field_Checkbox | Classic checkbox |
Form_Field::TYPE_RADIO_BUTTON | Jet\Form_Field_RadioButton | Select one option from multiple options using the radio button. |
Form_Field::TYPE_TEXTAREA | Jet\Form_Field_Textarea | Text field |
Form_Field::TYPE_WYSIWYG | Jet\Form_Field_WYSIWYG | HTML WYSIWYG editor |
Form_Field::TYPE_PASSWORD | Jet\Form_Field_Password | Password field |
Form_Field::TYPE_FILE | Jet\Form_Field_File | Field for uploading one or more files |
Form_Field::TYPE_FILE_IMAGE | Jet\Form_Field_FileImage | Field for uploading one or more images |
Of course, you can create your own new field types.
Overview of methods
Obecné
General methods are mainly related to form definition.
Method | Meaning of |
---|---|
public __construct( string $name, string $label=\'\', mixed $default_value=\'\', bool $is_required=false ) |
Parameters:
|
public setup( array $properties ) : void |
Sets the properties of the array. The method is intended for internal use - for automatic form generation. It should not be used outside this purpose. |
public setForm( Form $form ) : void |
Sets the form instance to which the field belongs. Method for internal use. It should not be used in the application space. |
public getForm( ) : Form |
Returns the form instance to which the field belongs |
public getName( ) : string |
Returns the name of the field. |
public setName( string $name ) : void |
Sets the name of the field. |
public getId( ) : string |
Returns the field ID (for HTML and JavaScript). |
public getTagNameValue( ) : string |
Returns the value of the HTML field name. |
public setDefaultValue( mixed $default_value ) : void |
Sets the default value. |
public getDefaultValue( ) : mixed |
Returns the default value. |
public setLabel( string $label ) : void |
Sets the field label. |
public getLabel( ) : string |
Returns the set field label - already translated. |
public setPlaceholder( string $placeholder ) : void |
Sets the placeholder text to the "background" of the input field. |
public getPlaceholder( ) : string |
Returns the placeholder - the text "in the background" of the input field - already translated. |
public setHelpText( string $help_text ) : void |
Sets the hint for the field. |
public getHelpText( ) : string |
Returns the set help for the field - already translated and completed with data. |
public setHelpData( string $help_text ) : void |
Sets the data to the help field. Example of use:
$int_field = new Form_Field_Int( 'int', 'Int' );
. |
public getHelpData( ) : string |
Returns data to the help field. |
public setIsRequired( string $required ) : void |
Sets whether the field is/is not mandatory. |
public getIsRequired( ) : bool |
Indicates whether the field is/is not required. |
public getIsReadonly( ) : bool |
Sets whether the field is/is not read-only. |
public setIsReadonly( bool $is_readonly ) : void |
Indicates whether the field is/is not read-only. |
public jsonSerialize( ) : array |
The form instance can be passed to the json_encode function. |
Input capturing and validation
The following is an overview of methods related to capturing values from input and validating data.
Method | Meaning of |
---|---|
public catchInput( Data_Array $data ) : void |
Internal use method called by the form when capturing input. |
public setValidator( callable $validator ) |
Sets the validator. The validator prototype is:
function( Form_Field $field ) : bool
|
public getValidator( ) : callable|null |
Returns the set validator. |
public getRequiredErrorCodes( ) : array |
Returns a list of error codes for which the field will require an error message definition. |
public getErrorMessages( ) : array |
Returns set error messages. |
public setErrorMessages( array $error_messages ) : void |
Sets error messages in the form of an associated field, where the key is the error code and the value of the error message. |
public getErrorMessage( string $code, array $data=[] ) : string|bool |
Returns the generated error message for the given error code. The message is already translated and updated with any data. |
public setError( string $code, array $data=[] ) : void |
A method designed primarily for use in validators. It sets the field to the error state - i.e. it determines that an error occurred during validation. |
public getAllErrors( ) : Form_ValidationError[] |
Returns a list of all validation errors. |
public getLastErrorCode( ) : string |
Returns the code of the last recorded validation error. |
public getLastErrorMessage( ) : string |
Returns the error message of the last recorded validation error. |
protected setIsValid( ) : void |
The opposite of the setError method. It sets the array to the error-free state. It is also a method designed primarily for validators. |
public isValid( ) : bool |
Induces whether the field is/is not valid. |
public validate( ) : bool |
Performs the validation process and immediately indicates whether the field is valid. Primarily this is a method for internal use called by the form. |
Working with captured data
These methods are related to working with and passing captured data.
Method | Meaning of |
---|---|
public hasValue( ) : bool |
Indicates whether the value was captured at all. That is, whether the value existed at all in the input data. |
public getValue( ) : mixed |
Returns the processed captured value. That is, the number is converted to a number, the string is encoded using HTML special chars, and so on. |
public getValueRaw( ) : mixed |
Returns the unprocessed captured value as it was on the input. This method must not be used unless you are absolutely sure you need it. But for example, to capture the contents of a WYSIWYG editor (where HTML is the core of its function), its use is necessary. |
public setValue( mixed $value ) : void |
Sets the processed value of the field. Method for internal use and for validators. |
public setFieldValueCatcher( callable $catcher ) : void |
Sets the value capturer. The prototype of the catcher is:
function (mixed $value) : void
|
public getFieldValueCatcher( ) : callable|null |
Returns the set value catcher. |
public catchFieldValue( ) : void |
Performs a value capture. A method for internal use that is called by the form. |
Translation
Method | Meaning of |
---|---|
public setDoNotTranslateLabel( bool $do_not_translate_label ) : void |
This method allows you to override the element label translation. |
public getDoNotTranslateLabel( ) : bool |
Indicates whether the element label translation is suppressed. |
public _( string $phrase, array $data=[] ) : string |
Translates the given text according to form settings. The method is primarily used for internal purposes. |
Displaying / rendering
Finally, methods related to displaying / rendering the form field.
Method | Meaning of |
---|---|
public __toString( ) : string |
The element can be directly converted to a string and thus displayed. The render method is called. |
public render( ) : string |
It generates HTML code representing the form field according to all settings and returns the result as a return value. Practically it is a shortcut of the call: $field->renderer()->render(); |
public renderer( ) : Form_Renderer_Field |
Access to the main form field renderer. |
public row( ) : Form_Renderer_Field_Row |
Access to the form field row renderer which can be used to further set the row or display it individually. Practically it is a shortcut of the call: $field->renderer()->row(); |
public container( ) : Form_Renderer_Field_Container |
Access to the form field container renderer, which can be used to further configure the container or display it individually. Practically it is a shortcut call: $field->renderer()->container(); |
public error( ) : Form_Renderer_Field_Error |
Access to the error message renderer, which can be used to further configure the error message or display it individually. Practically it is a shortcut of the call: $field->renderer()->error(); |
public label( ) : Form_Renderer_Field_Label |
Access to the label renderer, which can be used to further set the label or display it individually. Practically it is a shortcut call: $field->renderer()->label(); |
public help( ) : Form_Renderer_Field_Help |
Access to the help renderer which can be used to further set the label or display it individually. Practically it is a shortcut call: $field->renderer()->help(); |
public input( ) : Form_Renderer_Field_Input |
Access to the renderer of the input field itself, which can be used to further set the input field or display it individually. Practically it is a shortcut of the call: $field->renderer()->input(); |