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

nitinvismaad's avatar

Sending data from one page Form to second page form to third where submit data

Hi, I need to send data from one page form(1 input) > in Page 2 (Add more info in inputs and text area) > page 3 (Preview & Submit).

First page user submit a url in an input

Second page user submit the url(picked from first page) related information like Title, Description, Selects a category, add tags etc. All in inputs and textarea.

Third page for final view of submitted information so far and submit it into the DB.

But the second page won't go to third page it gives 404 error.

Routes Code

Route::get('/submit', 'SubmitLinks@index')->middleware('auth');
Route::post('/submit2', 'SubmitLinks@submitUrl')->middleware('auth');
Route::post('/submit3', 'SubmitLinks@submitData')->middleware('auth');

Controller Code

namespace App\Http\Controllers;
use DB;
use App\Category; 
use Illuminate\Http\Request;

class SubmitLinks extends Controller
{
     public function __construct()
    {
        $this->middleware('auth');
    }
    
    public function index() {
        return view('submit');
        $link = $request->input('link');
        $request->session()->put('link',$link);
   }
    /**
     * Submit a new Url.
     *
     * @param  Request  $request
     * @return Response
     */
    public function submitUrl(Request $request)
    {
        
        $categories = DB::table('categories')->get();
        $validatedData = $request->validate([
            'link' => 'required|unique:links|min:5|active_url',
        ]);
        
        $link = $request->session()->get('link');
        
        $title = $request->input('title');
        $category = $request->input('category');
        $description = $request->input('description');
        $tags = $request->input('tags');
        
        $request->session()->put('title',$title);
        $request->session()->put('category',$category);
        $request->session()->put('description',$description);
        $request->session()->put('tags',$tags);
            return view('submit2')->with('categories', $categories)->with('link', $link);
    }

    public function submitData(Request $request)
    {
        $validatedData = $request->validate([
            'title' => 'required|between:15,150',
            'category' => 'required',
            'description' => 'required|between:250,500',
            'tags' => ['required'],
        ]);

        $link = $request->session()->get('link');
        $title = $request->session()->get('title');
        $category = $request->session()->get('category');
        $description = $request->session()->get('description');
        $tags = $request->session()->get('tags');
        return view('submit3');    
    }

Both first and second pages have forms with Post method

First Page
<form action="submit2" method="post" >
@csrf
<input type="text" name="link">
</form>

Second page
<form action="submit3" method="post" >
@csrf
<input type="text" name="title" value="{{ old('title') }}>
<select class="form-control" id="category">
<option value="">Select a Category</option>
*
*
*
</select>
<input type="text" name="tags" value="{{ old('tag') }}>
<textarea name="description">{{ old('description') }}</textarea>
<input type="hidden" name="url" value="{{$link}}">
</form>

I am also trying to get data with session but it still giving the same 404 error or if I change the route to get from post the error I get is.

The POST method is not supported for this route. Supported methods: GET, HEAD. What should be done?

0 likes
5 replies
mstrauss's avatar

Hi @nitinvismaad

It could have something to do with the below validation line from your submitData method:

'tags' => ['required'],

Try changing it to:

'tags' => 'required',

I think you are getting the 404 (page not found) code though because Laravel isn't sure where to redirect the request to display the errors. I think you would have the same issue on your second request as well if the validation requirements were not met during that request cycle.

nitinvismaad's avatar

Changed it but still the same error. I guess it has to do something related to form Post method. That it can't get the view and post the form value at the same time or something like that. Do you have any idea about it?

mstrauss's avatar

Perhaps return the view in the other actions so Laravel know where to redirect the user, like this:

    public function submitUrl(Request $request)
    {
        
        $categories = DB::table('categories')->get();
        $validatedData = $request->validate([
            'link' => 'required|unique:links|min:5|active_url',
        ]);
        
        $link = $request->session()->get('link');
        
        $title = $request->input('title');
        $category = $request->input('category');
        $description = $request->input('description');
        $tags = $request->input('tags');
        
        $request->session()->put('title',$title);
        $request->session()->put('category',$category);
        $request->session()->put('description',$description);
        $request->session()->put('tags',$tags);
    return view('submit');
    }

    public function submitData(Request $request)
    {
        $validatedData = $request->validate([
            'title' => 'required|between:15,150',
            'category' => 'required',
            'description' => 'required|between:250,500',
            'tags' => 'required',
        ]);

        $link = $request->session()->get('link');
        $title = $request->session()->put('title');
        $category = $request->session()->put('category');
        $description = $request->session()->put('description');
        $tags = $request->session()->put('tags');      
    return view('submit');
    }

nitinvismaad's avatar

Sorry I missed that in the code, it is already in the code and i have updated my question. Thanks. Can you look at it again?

BugzBrown's avatar

If you are getting a 404 it would imply your are being redirected somewhere. Check your logs to see if there is any 301s. I would start off by removing the auth middleware and see if the problem persists. The less moving parts you have, the easier to debug.

Please or to participate in this conversation.