1. Go to this page and download the library: Download rs/form-laravel 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/ */
rs / form-laravel example snippets
namespace App\Http\Formlets;
use RS\Form\Formlet;
class UserForm extends Formlet{
/**
* Prepare the form with fields
*
* @return void
*/
public function prepare():void {
}
/**
* Validation rules that apply to the form.
*
* @return array
*/
public function rules(): array
{
return [];
}
}
class TestForm extends Formlet{
public function __construct(){
$this->setPrefix('test');
}
}
namespace App\Http\Formlets;
use RS\Form\Formlet;
use RS\Form\Fields\Input;
class UserForm extends Formlet{
/**
* Prepare the form with fields
*
* @return void
*/
public function prepare():void {
$field = new Input('text','name');
$this->add($field);
}
/**
* Validation rules that apply to the form.
*
* @return array
*/
public function rules(): array
{
return [
'name'=> '
namespace App\Http\Controllers;
use Illuminate\Routing\Controller as BaseController;
use App\Http\Formlets\UserForm;
class UserController extends BaseController {
public function create(UserForm $form)
{
$data = $form->route('users.store')->build();
return view('user.create',$data);
}
public function store(UserForm $form)
{
$form->store();
}
}
namespace App\Http\Formlets;
use RS\Form\Formlet;
use RS\Form\Fields\Input;
class UserForm extends Formlet{
public function __construct(User $user) {
$this->model = $user;
}
public function prepare(): void {
// Prepare the fields.
}
}
namespace App\Http\Formlets;
use RS\Form\Formlet;
class UserForm extends Formlet{
public function prepare(): void {
// Prepare the fields.
}
protected function prepareForValidation()
{
$this->mergeInput(['name'=>'John']);
}
}
bash
php artisan vendor:publish --tag=form
sh
php artisan make:formlet UserForm
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.