diff --git a/README.md b/README.md index b5deca3e..deec29a4 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ import Clipboard from '@ryangjchandler/alpine-clipboard' + import "../../vendor/aerni/livewire-forms/resources/dist/js/livewire-forms"; Alpine.plugin(Clipboard) - + Livewire.start() ``` @@ -47,14 +47,14 @@ Then, add the `{{ livewire:styles }}` and `{{ livewire:scriptConfig }}` tags to {{ livewire:styles }} - + @livewireStyles {{ livewire:scriptConfig }} - + @livewireScriptConfig @@ -128,11 +128,12 @@ Use the `view` and `theme` parameters if you want to use a view or theme that is #### Available Properties -| Property | Description | -| -------- | ------------------------------------------------- | -| `handle` | The handle of the form you want to use (required) | -| `view` | The component view you want to use (optional) | -| `theme` | The theme you want to use (optional) | +| Property | Description | +| ---------- | --------------------------------------------------------------------- | +| `handle` | The handle of the form you want to use (required) | +| `view` | The component view you want to use (optional) | +| `theme` | The theme you want to use (optional) | +| `redirect` | Redirect the user to this URL after successfull submission (optional) | ## Views @@ -419,7 +420,7 @@ Lastly, we need to render our new `ContactForm` component in the template. ### Validation Rules -You can use any validation rule you want. Simply add it to the field in the form blueprint or use the blueprint builder in the CP. +You can use any validation rule you want. Simply add it to the field in the form blueprint or use the blueprint builder in the CP. To validate against the value of another field, you need to get its value like in the following example: diff --git a/resources/views/dynamic-form.blade.php b/resources/views/dynamic-form.blade.php index 4d512e6e..9776dd50 100644 --- a/resources/views/dynamic-form.blade.php +++ b/resources/views/dynamic-form.blade.php @@ -1,3 +1,3 @@
- +
diff --git a/src/Commands/form.stub b/src/Commands/form.stub index 5c8fad9a..facd3656 100644 --- a/src/Commands/form.stub +++ b/src/Commands/form.stub @@ -25,6 +25,7 @@ class [class] extends BaseForm // $this->theme = 'secondary'; // $this->type = 'wizard'; // $this->view = 'default'; + // $this->redirect = 'thank-you'; // } /* diff --git a/src/Livewire/BaseForm.php b/src/Livewire/BaseForm.php index c455a1ac..2601c1f0 100644 --- a/src/Livewire/BaseForm.php +++ b/src/Livewire/BaseForm.php @@ -8,6 +8,7 @@ use Aerni\LivewireForms\Livewire\Concerns\WithForm; use Aerni\LivewireForms\Livewire\Concerns\WithHandle; use Aerni\LivewireForms\Livewire\Concerns\WithMessages; +use Aerni\LivewireForms\Livewire\Concerns\WithRedirect; use Aerni\LivewireForms\Livewire\Concerns\WithSections; use Aerni\LivewireForms\Livewire\Concerns\WithSteps; use Aerni\LivewireForms\Livewire\Concerns\WithTheme; @@ -27,6 +28,7 @@ class BaseForm extends Component use WithSections; use WithSteps; use WithMessages; + use WithRedirect; use SubmitsForm; public function render(): View diff --git a/src/Livewire/Concerns/HandlesSuccess.php b/src/Livewire/Concerns/HandlesSuccess.php index 2cb754ea..177d8315 100644 --- a/src/Livewire/Concerns/HandlesSuccess.php +++ b/src/Livewire/Concerns/HandlesSuccess.php @@ -6,9 +6,14 @@ trait HandlesSuccess { - protected function handleSuccess(): self + protected function handleSuccess(): ?self { session()->flash('success', $this->successMessage()); + session()->flash('submission', $this->submission); + + if (! empty($this->redirect)) { + return $this->redirect($this->redirect); + } if (! $this->isWizardForm()) { $this->resetForm(); diff --git a/src/Livewire/Concerns/WithRedirect.php b/src/Livewire/Concerns/WithRedirect.php new file mode 100644 index 00000000..c7d1f328 --- /dev/null +++ b/src/Livewire/Concerns/WithRedirect.php @@ -0,0 +1,11 @@ +