1. Go to this page and download the library: Download helmut/forms 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/ */
helmut / forms example snippets
// File: app/Forms/Form.php
namespace App\Forms;
class Form extends \Helmut\Forms\Form {
}
$form = new \App\Forms\Form;
// File: app/Http/routes.php
Route::any('/', function(\App\Forms\Form $form) {
// Now you can access $form
});
// File: app/Forms/Login.php
namespace App\Forms;
class Login extends Form {
public function define()
{
$this->email('email')->label('Email Address')->;
}
}
$form = new \App\Forms\Login;
if ($form->completed()) {
// The form has been submitted and passed validation
}
echo $form->render();
// File: app/Http/Controllers/LoginController.php
class LoginController extends Controller {
public function handleLoginForm(\App\Forms\Login $form)
{
if ($form->completed()) {
// The form has been submitted and passed validation
}
return view('login.form', compact('form'));
}
}
// Fields
$form->button('register') // Create a button
$form->text('foo') // Create a text field
$form->name('foo') // Create a name field
$form->email('foo') // Create an email field
$form->number('foo') // Create a numeric field
$form->password('foo') // Create a password field
$form->paragraph_text('foo') // Create paragraph text field
$form->checkbox('foo') // Create a checkbox field
$form->checkboxes('foo') // Create checkboxes field
$form->dropdown('foo') // Create dropdown field
$form->search('foo') // Create a search box field
// Applying Modifiers
$form->text('foo')->
$form->invalid('name')
$form->submitted() // Check if the form has been submitted
$form->submitted('register') // Check if submitted using a specific button
$form->completed() // Check if submitted and valid
// Retrieving Values
$form->all() // Get all the values
$form->get('foo') // Get the foo field values
$form->get('foo', 'bar') // Get the foo[bar] field value
// Filling Models
$form->fill($user) // Fills all fields in user model
$form->fill($user, 'name') // Fills just the name fields
$form->fill($user, ['name', 'email']) // Fills just the name and email fields
$form->button('foo')->label('Foo')
$form->submitted('foo') // Returns true if form was submitted using this button
$form->completed('foo') // Returns true if form both submitted and valid
$form->checkbox('foo')->label('Foo')->Check the box
$form->checkbox('foo')->unchecked() // Uncheck the box
$form->get('foo') // Returns true/false
$form->checkboxes('foo')->label('Foo')->options(['bar' => 'Bar', 'baz' => 'Baz'])->)->checked(['bar']) // Check some of the boxes
$form->checkboxes('foo')->unchecked() // Uncheck all the boxes
$form->checkboxes('foo')->unchecked(['baz']) // Uncheck some of the boxes
$form->get('foo') // Returns ['foo_bar' => false, 'foo_baz' => false]