Slug customisation (#755)
* Enhance Form Slug Handling and Validation Logic - Updated `FormController.php` to conditionally set the form slug based on the `self_hosted` configuration, ensuring proper slug assignment during form creation and updates. - Introduced `CustomSlugRule.php` to validate custom slugs, enforcing format and uniqueness constraints, and integrated this rule into `UserFormRequest.php`. - Enhanced the `FormCustomSeo.vue` component to include a field for custom URL slugs, improving user experience by allowing users to define unique identifiers for their forms. - Updated API routes to apply middleware for form updates, ensuring proper form resolution during requests. These changes aim to improve the functionality and user experience related to form slug management and validation. * Test case for Custom slug * Update OpenCompleteForm and FormCustomSeo for Improved Functionality and Clarity - Modified `OpenCompleteForm.vue` to ensure `submissionId` is correctly referenced as `submissionId.value`, enhancing data handling during form initialization. - Updated `FormCustomSeo.vue` to rename "Custom URL Slug" to "Custom Form URL" for better clarity and user understanding, ensuring consistent terminology across the application. - Enhanced `useFormInitialization.js` to include `submission_id` in the data passed to `form.resetAndFill`, improving the accuracy of form data handling. These changes aim to improve the functionality and user experience of the form components by ensuring correct data references and clearer labeling. --------- Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
@@ -121,6 +121,11 @@ class FormController extends Controller
|
||||
'creator_id' => $request->user()->id,
|
||||
]));
|
||||
|
||||
if (config('app.self_hosted') && !empty($formData['slug'])) {
|
||||
$form->slug = $formData['slug'];
|
||||
$form->save();
|
||||
}
|
||||
|
||||
if ($this->formCleaner->hasCleaned()) {
|
||||
$formStatus = $form->workspace->is_trialing ? 'Non-trial' : 'Pro';
|
||||
$message = 'Form successfully created, but the ' . $formStatus . ' features you used will be disabled when sharing your form:';
|
||||
@@ -150,6 +155,8 @@ class FormController extends Controller
|
||||
return !Str::of($field['type'])->startsWith('nf-') && !in_array($field['id'], collect($formData['properties'])->pluck('id')->toArray());
|
||||
})->toArray());
|
||||
|
||||
$form->slug = (config('app.self_hosted') && !empty($formData['slug'])) ? $formData['slug'] : $form->slug;
|
||||
|
||||
$form->update($formData);
|
||||
|
||||
if ($this->formCleaner->hasCleaned()) {
|
||||
|
||||
@@ -4,12 +4,14 @@ namespace App\Http\Requests;
|
||||
|
||||
use App\Http\Requests\Workspace\CustomDomainRequest;
|
||||
use App\Models\Forms\Form;
|
||||
use App\Rules\CustomSlugRule;
|
||||
use App\Rules\FormPropertyLogicRule;
|
||||
use App\Rules\PaymentBlockConfigurationRule;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* Abstract class to validate create/update forms
|
||||
@@ -18,6 +20,13 @@ use Illuminate\Validation\Rule;
|
||||
*/
|
||||
abstract class UserFormRequest extends \Illuminate\Foundation\Http\FormRequest
|
||||
{
|
||||
public ?Form $form;
|
||||
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$this->form = $request?->form ?? null;
|
||||
}
|
||||
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$data = $this->all();
|
||||
@@ -76,8 +85,8 @@ abstract class UserFormRequest extends \Illuminate\Foundation\Http\FormRequest
|
||||
$workspace = null;
|
||||
|
||||
// For update requests, try to get the workspace from the form
|
||||
if ($this->route('form')) {
|
||||
$workspace = $this->route('form')->workspace;
|
||||
if ($this->form) {
|
||||
$workspace = $this->form->workspace;
|
||||
}
|
||||
// For create requests, get the workspace from the workspace parameter
|
||||
elseif ($this->route('workspace')) {
|
||||
@@ -186,6 +195,7 @@ abstract class UserFormRequest extends \Illuminate\Foundation\Http\FormRequest
|
||||
'password' => 'sometimes|nullable',
|
||||
'use_captcha' => 'boolean',
|
||||
'captcha_provider' => ['sometimes', Rule::in(['recaptcha', 'hcaptcha'])],
|
||||
'slug' => [new CustomSlugRule($this->form)],
|
||||
|
||||
// Custom SEO
|
||||
'seo_meta' => 'nullable|array',
|
||||
|
||||
Reference in New Issue
Block a user