grozavule
1 month ago
206
4
Laravel

Forms, Query Strings, and Controller Parameters

Posted 1 month ago by grozavule

I have an HTML form that submits a GET request. Below is the Blade template for it:

@extends('base')

@section('content')
    @error('serial')
    <div class="alert alert-danger">{{ $message }}</div>
    @enderror
    <div class="row">
        <p>Type a part number into the box and press "Generate Report" (Example:
            <a href="{{ route('weldtub.show', ['serial' => '90114-624']) }}"> 90114-624</a>).</p>
        <p>Printing is optimized for the Chrome browser.
            <a href="javascript:window.print()"><em class="fi-print"></em> Click here to print.</a></p>
        <p>To print select tubs type desired page numbers under print preview (Example: 1-3 or 1,2,3)</p>
    </div>
    <div class="row">
        <form action="{{ route('weldtub.show', ['serial'])  }}" method="get">
            <label for="serial">Serial Number:</label>
            <input type="text" name="serial" value="{{ old('serial') or '' }}">
            <input type="submit" value="Generate" class="button postfix">
            @csrf
        </form>
    </div>
@endsection

The route definition is as follows:

Route::get('/fabrication/weldtub/{serial}', '[email protected]')->name('weldtub.show');

When the form submits, I would like it to use this route instead of appending a query string the the URL. How can I do that? If this isn't the right way to make this work, please point me in the right direction.

Please sign in or create an account to participate in this conversation.