apishka / form
Apishka forms
1.2.2
2018-02-14 20:28 UTC
Requires
- php: >=7
- apishka/easy-extend: *
- apishka/transformer: ^3.0.0
Requires (Dev)
- apishka/cs: ^1.0.0
- giggsey/libphonenumber-for-php: ^7.0.0
- phpunit/phpunit: ^6.0.6
Suggests
- giggsey/libphonenumber-for-php: To use Apishka_Form_Field_Phone
This package is auto-updated.
Last update: 2024-10-29 04:53:07 UTC
README
class MyForm extends Apishka_Form_FormAbstract { /** * Returns form structure * * @return array */ public function processStructure() { // This will add signature field to form, to determine when form was posted, // don't forger to include 'signature' in your markup parent::processStructure(); // We can add simple string field $this->addField( Apishka_Form_Field_String::apishka('string_field') ); // We add simpel int field $this->addField( Apishka_Form_Field_Int::apishka('int_field') ); } }
Basic field usage
Each field has functions to manipulate
$field = Apishka_Form_Field_String::apishka('field_name') // By default all fields have unique ID, but if you want to // set some specific ->setId('some_id') // You can mark field as required ->setRequired(true) // Returns value if field not presented in request ->setDefault('some_string') // Set current field value ->setValue('some_value') // Add transformation on value to the end of transformations list ->pushTransformation( 'Transform/Length', [ 'min' => 10, 'max' => 20, ] ) // Unshift transformation to transformations list ->pushTransformation( 'Transform/Callback', [ 'callback' => function($value) { return mb_strtolower($value); } ] ) ;