在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:orchestral/html开源软件地址:https://github.com/orchestral/html开源编程语言:PHP 100.0%开源软件介绍:HTML Component for Orchestra PlatformHTML Component extends the functionality of Version Compatibility
InstallationTo install through composer, run the following command from terminal: composer require "orchestra/html" ConfigurationNext add the service provider in 'providers' => [
// ...
Orchestra\Html\HtmlServiceProvider::class,
], AliasesYou might want to add the following to class aliases in 'aliases' => [
// ...
'Form' => Orchestra\Support\Facades\Form::class,
'HTML' => Orchestra\Support\Facades\HTML::class,
'Table' => Orchestra\Support\Facades\Table::class,
], Usage
Create HTMLCreate a HTML tag from within your libraries/extension using following code: return HTML::create('p', 'Some awesome information'); Will return You can customize the HTML attibutes by adding third parameter. return HTML::create('p', 'Another awesomeness', ['id' => 'foo']); Will return Raw HTML EntitiesMark a string to be excluded from being escaped. return HTML::link('foo', HTML::raw('<img src="foo.jpg">')); Will return This also can be dynamically done via. return HTML::link('foo', HTML::image('foo.jpg')); Decorate HTMLDecorate method allow developer to define HTML attributes collection as return HTML::decorate(['class' => 'foo'], ['id' => 'foo', 'class' => 'span5']); Will return It also support replacement of default attributes if such requirement is needed. return HTML::decorate(['class' => 'foo !span5'], ['class' => 'bar span5']); Will return FormsCreating forms couldn't be any easier using Orchestra's HTML package. Let's get started. Creating a new FormTo create a new form, use the return Form::of('users'); Form AttributesTo customize your forms attributes, call the return Form::of('users', function ($form) {
$attributes = [
'method' => 'PATCH',
'id' => 'user-login-form',
'class' => 'form-horizontal',
];
$form->attributes($attributes);
}); Specifying the Form layoutTo specify the layout of the form, call the return Form::of('users', function ($form) {
$form->layout('layouts.form');
}); Adding FieldsTo add fields to our form, we'll pass in a closure into the second parameter, and call the return Form::of('users', function ($form) {
$form->fieldset(function ($fieldset) {
$fieldset->control('input:text', 'username');
$fieldset->control('input:email', 'email');
$fieldset->control('input:password', 'password');
});
}); Available Fields// A text field
$form->control('input:text', 'name');
// A password field
$form->control('input:password', 'name');
// A file field
$fieldset->control('input:file', 'name');
// A textarea filed
$form->control('textarea', 'name');
// A select field
$form->control('select', 'name')
->options(['one', 'two', 'three']); Adding Labels to FieldsTo add a label onto a form control, use the method $form->fieldset(function ($fieldset) {
$form->control('input:text', 'username')
->label('Username');
$form->control('input:email', 'email')
->label('Email');
$form->control('input:password', 'password')
->label('Password');
}); Adding Default Values to FieldsTo add a default value to the field, use the method $form->fieldset(function ($fieldset) {
$form->control('input:text', 'username')
->label('Username')
->value(Auth::user()->username);
$form->control('input:email', 'email')
->label('Email')
->value(Auth::user()->email);
$form->control('input:password', 'password')
->label('Password');
}); Changing the submit button labelTo change the submit button label, modify the FormGrid property return Form::of('users', function ($form) {
// The form submit button label
$form->submit = 'Save';
$form->fieldset(function ($fieldset) {
$form->control('input:text', 'username');
$form->control('input:email', 'email');
$form->control('input:password', 'password');
});
}); Customizing the form control attributesTo customize the form controls attributes, call the $attributes = [
'placeholder' => 'Enter your username',
'class' => 'form-control',
];
$form->control('input:text', 'username')
->attributes($attributes); Customizing the form control itself$form->control('input:email', 'email', function ($control) {
$control->field(function ($row) {
return "<input type='email' name="email" value='$row->email'>";
});
}); You could also create a use Illuminate\Contracts\Support\Renderable;
class EmailAddressField implements Renderable
{
public function __construct($name, $value)
{
$this->name = $name;
$this->value = $value;
}
public function render()
{
return sprintf('<input type="email" name="%s" value="%s">', $this->name, $this->value);
}
} And you can simply register it via: $form->control('input:email', 'email', function ($control) {
$control->field(function ($row) {
return new EmailAddressField('email', $row->email);
});
}); Displaying your formTo display your form, simply display it in your view with unescaped blade tags: public function index()
{
$form = Form::of('users', function ($form) {
$form->fieldset(function ($fieldset) {
$form->control('input:text', 'username');
$form->control('input:email', 'email');
$form->control('input:password', 'password');
});
});
return view('index', compact('form'));
} // In index.blade.php
{!! $form !!} |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论