calderawp / forms
Forms
0.2.0
2019-02-14 17:10 UTC
Requires
- php: ^7.2
- psr/container: ^1.0
Requires (Dev)
- php: ^7.2
- mockery/mockery: ^1.2
- phpunit/phpunit: ^7.3
- squizlabs/php_codesniffer: 3.*
This package is auto-updated.
Last update: 2024-10-23 06:59:23 UTC
README
This is the forms package of the Caldera Framework and provides form functionality, including entry tracking. This is not Caldera Forms.
👀🌋 This Is A Module Of The Caldera Framework
-
🌋 Find Caldera Forms Here:
-
🌋 Issues and pull requests, should be submitted to the main Caldera repo.
Install
- Add to your package:
composer require calderawp/forms
- Install for development:
git clone git@github.com:CalderaWP/forms.git && composer install
Examples
Form Model
- Simple Example
$model = FormModel::fromArray([
'id' => 'cf1',
'name' => 'Contact Form',
'fields' => [],
'settings' => []
]);
- Example 2
//Create model
$form = \calderawp\caldera\Forms\FormModel::fromArray([
'id' => 'cf1',
'name' => 'Contact Form'
]);
//Email field
$emailField = \calderawp\caldera\Forms\FieldModel::fromArray([
'id' => 'fld1',
'type' => 'text',
'slug' => 'email',
'html5type' => 'email',
'label' => 'Your Email'
]);
//Checkbox with two options
$checkBoxField = \calderawp\caldera\Forms\FieldModel::fromArray(
[
'id' => 'fld2',
'type' => 'checkbox', //radio or select has same syntax for options
'label' => 'I agree to privacy policy',
'description' => 'Learn more by reading our privacy policy',
'options' =>[
[
'label' => 'Yes',
'value' => true
],
[
'label' => 'No',
'value' => false
]
]
]
);
//Add fields to form
$form
->addField($emailField)
->addField($checkBoxField);
Example With Many Fields
$array = [ 'id' => 'cf1', 'fields' => [ 'name' => [ 'id' => 'name', 'type' => 'input', 'label' => 'Your Name', 'required' => true, 'description' => 'Put your name here', 'config' => [ 'html5type' => '' ] ], 'numberOfItems' => [ 'id' => 'numberOfItems', 'type' => 'input', 'label' => 'Total', 'description' => 'How many items?', 'fieldConfig' => [ 'html5type' => 'number', 'attributes' => [ 'min' => 0, 'step' => 1 ] ] ], 'agreeToTerms' => [ 'id' => 'agreeToTerms', 'type' => 'select', 'label' => 'Agree to terms', 'description' => 'Compliance is mandatory', 'fieldConfig' => [ 'multiple' => false, 'options' => [ [ 'value' => true, 'label' => 'Yes' ], [ 'value' => false, 'label' => 'No' ] ] ] ] ], 'processors' => [ [ 'label' => 'Main Message', 'type' => 'testType', 'config' => [ 'fromName' => 'fld1', 'fromEmail' => 'roy@hiroy.club', ] ] ] ]; $model = FormModel::fromArray($array);
Field Model
- Text field
$field = \calderawp\caldera\Forms\FieldModel::fromArray([ 'id' => 'fld1', 'type' => 'input', 'slug' => 'name', 'label' => 'Your Name' ]);
- Email field
$field = \calderawp\caldera\Forms\FieldModel::fromArray([ 'id' => '', 'type' => 'input', 'html5type' => 'email', 'slug' => '', 'label' => '', 'description' => '' ]);
- Number field
$field = \calderawp\caldera\Forms\FieldModel::fromArray([ 'id' => '', 'type' => 'input', 'html5type' => 'number', 'slug' => '', 'label' => '', 'description' => '', 'attributes' => [ 'min' => 5, 'max' => 12 ] ]);
Testing
- Run unit tests
composer test:unit
- Run integration tests
composer test:integration
- Run acceptance tests
composer test:acceptance
License, Copyright, etc.
Copyright 2018+ CalderaWP LLC and licensed under the terms of the GNU GPL license. Please share with your neighbor.