FormBuilder

FormBuilder is an open source PHP form generator that can quickly generate modern form forms. You can also work with the open source project Xaboy /form-create to generate any Vue component

Making | document

Environmental requirements

  • PHP > = 5.4

The installation

Using composer:

$composer require xaboy/form - builder: ~ 2.0Copy the code

The document

The document

Support the UI

  • IView
  • ElementUI

Function is introduced

  • There are 17 common form components built in
  • Support for form validation
  • Support for generating any Vue component
  • Support for grid layouts
  • You can work with form-create to generate more complex forms

To generate the form

For example, ElementUI is used as follows:

use  FormBuilder\Factory\Elm;

$action = '/save.php';
$method = 'POST';

$input = Elm::input('goods_name'.'Trade Name')->required();
$textarea = Elm::textarea('goods_info'.'Product Profile');
$switch = Elm::switches('is_open'.'Open or not')->activeText('open')->inactiveText('off'); // Create form$form = Elm::form($action) - >setMethod($method); // Add a component$form->setRule([$input.$textarea]);
$form->append($switch); // Generate the form pageecho $formHtml = $form->view();
Copy the code

Form validation

mandatory

All built-in components support required validation

$input = Elm::input('goods_name'.'Trade Name');
/ / required
$input->required();
Copy the code

Create a mandatory validation rule

// Input component value type is string
$validate = Elm::validateStr();
$validate->required()->message('Please fill in the name of the commodity');
$input->appendValidate($validate);
//$input->appendValidates([$validate]);
//$input->validate([$validate]
Copy the code

Gets the validation rule corresponding to the component type

All built-in components support the createValidate method to obtain validation rules for a component. Note that validation rules for a component may have multiple types and need to be obtained after all of the component’s rules have been configured

$start = date('Y-m-d', strtotime('- 10day'));
$end = date('Y-m-d', time());
$dateRange = Elm::dateRange('start_time'.'Time interval', $start, $end);
$validate = $dateRange->createValidate();
Copy the code

The length or value must be within this range

$validate->range(1.10);
Copy the code

The length or value must be greater than this value

$validate->min(1);
Copy the code

The length or value must be less than this value

$validate->max(10);
Copy the code

The length or value must be equal to this value

$validate->length(10);
Copy the code

Values must be in the list

$list = [1.2.3.4];
$validate->enum($list);
Copy the code

The regular verification

$validate->pattern('^[A-Z]+$');
Copy the code

Validation failed error message

$validate->message('Input error');
Copy the code

Create rules

stringtype

$validate = Elm::validateStr();
//email
$validate = Elm::validateEmail();
//url
$validate = Elm::validateUrl();
Copy the code

arraytype

$validate = Elm::validateArr();
Copy the code

inttype

$validate = Elm::validateInt();
Copy the code

floattype

$validate = Elm::validateFloat();
Copy the code

float|inttype

$validate = Elm::validateNum();
Copy the code

Datetype

For example, DatePicker TimePicker

$validate = Elm::validateDate();
Copy the code

objecttype

$validate = Elm::validateObject();
Copy the code

Enumerated type

$validate = Elm::validateEnum()->enum(['1'.'2'.'3']);
Copy the code

Hex type

$validate = Elm::validateHex();
Copy the code

triggered

change

Validation is triggered when the value changes, by default

blur

Triggered when a component loses focus

submit

Triggered when the form is submitted

rendering