Download the PHP package hynek/hynek-form without Composer
On this page you can find all versions of the php package hynek/hynek-form. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package hynek-form
Laravel Form Package
This package provides a robust and flexible way to build and render forms in your Laravel applications. It offers a clear, object-oriented approach to defining your form structures, controls, and presentation.
Installation
You can install the package via Composer:
After installing, publish the package's configuration file and views (optional) using:
This will publish config/form.php and resources/views/vendor/form to your application.
Configuration
The package's configuration file, config/form.php, allows you to customize the default classes and views used for various form components.
Here's a breakdown of the available configuration options:
Usage
The core of this package revolves around the FormBuilder interface, which defines the methods for constructing your forms. You will typically interact with an implementation of this interface to define your forms.
Basic Form Creation
To create a new form, you would usually instantiate the FormBuilder (or its concrete implementation) and chain its methods.
FormBuilder Methods
The FormBuilder interface provides the following methods for building your forms:
addAttribute(string|array $name, ?string $value = null): static
Adds HTML attributes to the form element.
$name: The attribute name (string) or an associative array of attributes.$value: The attribute value (if$nameis a string).
removeAttribute(string $name): static
Removes an HTML attribute from the form element.
$name: The name of the attribute to remove.
container(ElementContainer $container): static
Sets the container for the element. This allows you to wrap your form elements in custom HTML structures.
$container: An instance ofElementContainer.
name(string $name): static
Sets the name of the form element. (Useful for the form itself if it's treated as an element).
$name: The name string.
id(string $id): static
Sets the HTML id attribute of the form element.
$id: The ID string.
view(string $view): static
Sets a custom Blade view for rendering the element.
$view: The Blade view path (e.g.,'custom.form.template').
getName(): ?string
Gets the name of the form element.
getContainer(): ?ElementContainer
Gets the container of the form element.
action(string $action): static
Sets the action attribute for the form.
$action: The URL where the form data will be submitted.
method(string $method): static
Sets the method attribute for the form (e.g., POST, GET).
$method: The HTTP method.
element(FormElement $element): static
Adds a form element (like an input, textarea, or select) to the form.
$element: An instance of a class implementingFormElement(e.g.,Input,Textarea).
getElements(): ElementsCollection
Retrieves a collection of all form elements added to the builder.
getRules(): Collection
Retrieves the validation rules associated with the form's elements. (Implementation dependent on how rules are attached to FormElement instances).
button(string $text, ?string $type = 'button'): static
Adds a button to the form.
$text: The text displayed on the button.$type: The button type (e.g.,'submit','button','reset'). Defaults to'button'.
getButtons(): ButtonsCollection
Retrieves a collection of all buttons added to the form.
enableAjax(): static
Enables AJAX/XHR submission for the form. This would typically add a specific attribute or class that your JavaScript can hook into.
disableAjax(): static
Disables AJAX/XHR submission for the form.
livewireSubmit(string $livewireSubmit): static
Integrates with Livewire by setting a wire:submit attribute on the form.
$livewireSubmit: The Livewire method to call on form submission (e.g.,'saveUser').
updateValue($elementName, $value): static
Updates the value of a specific form element.
$elementName: The name of the element whose value is to be updated.$value: The new value for the element.
Rendering Forms
Once you've constructed your form using the FormBuilder, you can render it in your Blade templates:
In your controller, you would pass the constructed form to the view:
Extending and Customizing
Custom Form Controls
You can create your own custom form controls by extending the Hynek\Form\Controls\Control class (or any existing control) and implementing the necessary methods. Once created, you can register your custom control in the config/form.php file under the controls array.
Then, in config/form.php:
Custom Views
If you've published the package's views, you can directly modify them in resources/views/vendor/form. Alternatively, you can create entirely new views and update the views array in config/form.php to point to your custom templates.
Custom Containers
Similar to controls, you can extend Hynek\Form\FormContainer or Hynek\Form\ControlContainer to create custom wrappers for your forms or individual controls. Then, update the default_form_container or default_control_container in your config/form.php.
3rd-party libraries
PHP / Laravel
- livewire/flux
JavaScript
- Vite
All versions of hynek-form with dependencies
hynek/hynek-macro Version dev-main
hynek/hynek-module-tools Version dev-main
livewire/flux Version ^2.2
livewire/livewire Version ^3.6
spatie/laravel-data Version ^4.17