Laravel post form is not submitting?

Didzis Zvaigzne

I want to make a form where you select what exercises you have done and afterwards add them to the database, but the problem is that I can't even submit my post form. The button does nothing when it is pressed.

This is my view file:

@extends('layouts.app')

    @section('content')
    <div class="container">
    <div class="row">

    <div class="col-md-8 col-md-offset-2">



        <div class="panel panel-default">
            <div class="panel-body">
                <h2>Excercise - {{$excercises[0]->hnro}}</h2>
                <hr>
                <div class="col-md-10">
                @if (session('error'))
                    <div class="alert alert-danger">
                        {{ session('error') }}
                    </div>
                @endif
                    @if (session('success'))
                        <div class="alert alert-success">
                            {{ session('success') }}
                        </div> 
                    @endif
                    
                <form class="form-horizontal" name="form" method="POST" action="{{ route('storeScores') }}">
                
                    <div class="form-group row">
                        <div class="col-md-12">
                        <input type="url" name="url" id="url" class="form-control" placeholder="Copy the URL here" required autofocus>
                        </div>
                    </div>
                
    </div>

    @foreach($excercises as $excercise)

    <div class="row">
    <div class="form-group col-md-3 col-md-offset-1">
    <select class="form-control" id="select{{$excercise->tnro}}" name="teht[]" required>
    <option value="">Excercise {{$excercise->tnro}}</option>
    <optgroup label="Choose your points">
    @for ($i=0; $i<=$excercise->maxpist;$i++)
    <option value="{{$i}}">{{$i}} points</option>
    @endfor
    </optgroup>


    </select>
    </div>
    </div>
    @endforeach



    <div class="form-group row">
                        <div class="col-md-5 col-md-offset-1">
                            <button type="submit" name="save" class="btn btn- 
   primary">Tallenna</button>
                        </div>
                    </div>

                            <input type="hidden" name="hnro" value="">
                            <input type="hidden" name="student_id" value="">

                </form>
            </div>
        </div>
    </div>
</div>
    </div>
    @endsection

This is my route:

Route::get('/addscoreform','HarkkaController@showExcercises');
Route::post('/addscoreform','HarkkaController@storeScores')->name('storeScores');

And this is my controller:

public function storeScores(Request $request)
{
    return redirect()->back()->with('success','Form has been sent...');
}

My problem is that I can't even display the success message after submit! It's like the button doesn't work!

James Clark Developer

It seems like you have tag nesting issues.

<form ...>
  <div class="form-group row">
    <div class="col-md-12">
      <input type="url" name="url" id="url" class="form-control" ...>
    </div>
  </div>          
</div>
...
</form>

What is the third closing? Ensure that the opening and closing tags are nested properly.

A few things which might help organize this better and make it easier to maintain are to eliminate any tags you can, and to break things down into smaller subviews and include statements as much as possible. Subviews are described at https://laravel.com/docs/master/blade#including-subviews.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related