PHP code example of revolution / laravel-laminas-form
1. Go to this page and download the library: Download revolution/laravel-laminas-form library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
revolution / laravel-laminas-form example snippets
namespace App\Http\Forms;
use Revolution\LaminasForm\Form;
use Laminas\Form\Element;
class SampleForm extends Form
{
/**
* Create a new form.
*
* @param null|string $name
*
* @return void
*/
public function __construct($name = null)
{
parent::__construct($name);
$this->setAttributes([
'action' => url('/'),
'method' => 'post',
]);
$name = new Element\Text('name');
$name->setAttributes([
'id' => 'name',
'class' => 'form-control',
'value' => old('name'),
]);
$name->setLabel('Your name');
$name->setLabelAttributes([
'class' => 'col-sm-2 col-form-label',
]);
$name->setOptions([
'wrapper-class' => 'mb-3 row',
'element-class' => 'col-sm-10',
]);
$this->add($name);
$this->add([
'type' => Element\Email::class,
'name' => 'email',
'attributes' => [
'id' => 'email',
'class' => 'form-control',
'value' => old('email'),
],
'options' => [
'label' => 'Your email address',
'label_attributes' => [
'class' => 'col-sm-2 col-form-label',
],
'wrapper-class' => 'mb-3 row',
'element-class' => 'col-sm-10',
],
]);
$this->add([
'type' => Element\Hidden::class,
'name' => '_token',
'attributes' => [
'value' => csrf_token(),
],
]);
$this->add([
'name' => 'send',
'type' => 'Submit',
'attributes' => [
'value' => 'Submit',
'class' => 'btn btn-primary',
],
]);
}
}
use App\Http\Forms\SampleForm;
public function __invoke()
{
$form = new SampleForm();
return view('form')->with(compact('form'));
}
use App\Http\Forms\SampleForm;
public function __invoke(SampleForm $form)
{
return view('form')->with(compact('form'));
}
{{ $form->render() }}
@php
$form->prepare();
@endphp
{!! $form->form()->openTag($form) !!}
{{ csrf_field() }}
<div class="mb-3 row">
<label for="name" class="col-sm-3 col-form-label">{!! $form->get('name')->getLabel() !!}</label>
<div class="col-sm-9">
{!! $form->formInput($form->get('name')) !!}
</div>
</div>
<div class="mb-3 row">
<label for="email" class="col-sm-3 col-form-label">{!! $form->get('email')->getLabel() !!}</label>
<div class="col-sm-9">
{!! $form->formInput($form->get('email')) !!}
</div>
</div>
<div class="mb-3 row">
<div class="col-sm-9 offset-sm-3">
{!! $form->formSubmit($form->get('send')) !!}
</div>
</div>
{!! $form->form()->closeTag($form) !!}
{{ $form->render('bootstrap5horizon') }}