1. Go to this page and download the library: Download aerni/livewire-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/ */
public function mountedFields(Collection $fields): void
{
$fields->get('name')->display('Your name');
}
public function formSubmitted(Submission $submission): void
{
$title = $submission->augmentedValue('entry')->value()->title;
$submission->set('entry_title', $title);
}
public function handle(FormSubmitted $event)
{
$event->submission; // The Submission object
}
namespace App\Fields;
use Aerni\LivewireForms\Fields\Select;
use Statamic\Facades\Entry;
class SelectProduct extends Select
{
protected string $view = 'select_product';
public function optionsProperty(): array
{
return Entry::whereCollection('products')
->mapWithKeys(fn ($product) => [$product->slug() => $product->get('title')])
->all();
}
}
namespace App\Livewire;
use Aerni\LivewireForms\Livewire\Form;
class ContactForm extends Form
{
protected array $models = [
'products' => \App\Fields\SelectProduct::class,
];
}
namespace App\Livewire;
use Aerni\LivewireForms\Livewire\Form;
class ContactForm extends Form
{
public function mountedFields(Collection $fields): void
{
$options = Entry::whereCollection('products')
->mapWithKeys(fn ($product) => [$product->slug() => $product->get('title')])
->all();
$fields->get('products')
->options($options)
->view('select_product');
}
}
protected $messages = [
'fields.name.value.
protected function messages(): array
{
return [
'fields.name.value.
return [
'contact' => [
'submit_button_label' => 'Contact now',
'success_message' => 'Thanks for contacting us. We will be in touch.',
'error_message' => 'There was an error with your submission:|There were :count errors with your submission:',
],
'newsletter' => [
'submit_button_label' => 'Signup now',
],
];