Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Drakdy's avatar

Auto-save form

Recently I found myself having to create a page that users can freely fill out, but I am struggling to understand how to make the page capable of saving changes in real-time.

The idea is that every time the user selects an option from a dropdown or types characters in a textarea, the state (the change) should be saved without the need to click a button or anything else.

I have already tried the following code, but I get a 419 error from the console, and the data is not being saved to the database.

HTML:

<tr>
    <th>@lang('quickadmin.inspections.fields.execution-date')</th>
    <td field-key='execution_date'>
        {!! Form::text('execution_date', old('execution_date'), [
            'class' => 'form-control date',
            'id' => 'execution_date',
            'placeholder' => '',
        ]) !!}
    </td>

    <th>@lang('quickadmin.inspections.fields.execution-hour')</th>
    <td field-key='execution_time'>
        {!! Form::text('execution_time', old('execution_time'), [
            'class' => 'form-control timepicker',
            'id' => 'execution_time',
            'placeholder' => '',
        ]) !!}
    </td>
</tr>

<tr>
    <th>Veicolo</th>
    <td field-key='vehicles' colspan="3">
        {!! Form::select('vehicles[]', $vehicles, old('vehicles'), ['class' => 'form-control select2', 'multiple' => 'multiple', 'id' => 'selectall-methods' ]) !!}
        <p class="help-block"></p>
        @if($errors->has('vehicles'))
            <p class="help-block">
                {{ $errors->first('vehicles') }}
            </p>
        @endif
    </td>
</tr>

<tr>
    <th>Trasferta [minuti]</th>
    <td field-key='trip_time' colspan="3">
        {!! Form::text('trip_time', old('trip_time'), [
            'class' => 'form-control',
            'id' => 'trip_time',
            'placeholder' => 'Esempio: 28 [min]',
        ]) !!}
    </td>
</tr>

<tr>
    <th>Descrizione dell'intervento</th>
    <td field-key='inspection_note' colspan="3">
        @if ($inspection->inspection_note != null)
            <textarea id="desc" class="form-control" style="width: 100%;resize: none;" rows="5" maxlength="80">{{ $inspection->inspection_note }}</textarea>
        @else
            <textarea id="desc" class="form-control" style="width: 100%;resize: none;" rows="5" placeholder="Descrizione intervento"
             maxlength="80"></textarea>
        @endif
    </td>
</tr>

Controller update (The code can't even enter it):

public function update(UpdateNewInspectionRequest $request, $id) { $inspection = NewInspection::findOrFail($id); $inspection->extra_vehicles()->sync(array_filter((array)$request->input('extra_vehicles'))); $inspection->update($request->all()); $inspection->save();

return back();

}

I don't know if it could be important, but the feature I'm trying to implement was present in an old version of the website on a different host. About 6 months ago, we changed hosts and migrated the site. It's possible that the issue lies in the change of a reference?

0 likes
5 replies
Snapey's avatar

So much easier with Livewire. Have you considered this?

1 like
Drakdy's avatar

@Snapey I've considered it, but it looks like I will need to rethink the entire section logic and that's not really affordable, this section of the web site contains a pretty complex code that I would prefer not to alter, and I don't know Livewire enough to tell how to implement it just to that page.

I may be wrong by the way.

For what I saw Livewire is like an external View that I can insert in the original one, and a Controller like file to place all the logic.

Is it enough to just do a copy/paste of the code or I'll need to re-elaborate it (SOAP interaction are not easy to manage)?

Please or to participate in this conversation.