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!
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.
Related
When I try to insert data into my database, Laravel does not insert the records, but it is strange because when I migrate the tables to be able to perform the database, Laravel creates them without any problem, I do not know what I can be doing wrong if the migration run but stored no
Route:
Route::post('/proyecto', [ctrlCars::class,'store'])->name('cars');
Controler:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\cars;
class ctrlCars extends Controller
{
public function store(Request $request){
$request->validate([
'carRegistration'=> ['required','min:6'],
'name'=> ['required','min:6'],
'fromProduction' => ['required','min:6'],
'stateStored'=> ['required'],
'model'=> ['required','min:4'],
'dateAssembled' => ['required'],
]);
$car = new cars;
$car->carRegistration = $request->carRegistration;
$car->name = $request->name;
$car->fromProduction = $request->fromProduction;
$car->stateStored = $request->stateStored;
$car->model = $request->model;
$car->dateAssembled = $request->dateAssembled;
$car-> save();
return redirect()->route('cars')->with('success','Registro guardado satisfactoriamente');
}}
Template:
#extends('header')
#section('content')
<div class="container w-10 mt-5 border p-4">
<form action="{{ route('cars') }}" method="POST">
#csrf
#if (session('success'))
<h6 class="alert alert-success">{{ session('success') }}</h6>
#endif
#error('carRegistration')
<h6 class="alert alert-danger">{{ $message }}</h6>
#enderror
<p class="h2">Registro vehiculos</p>
<br>
<div class="row">
<section class="col-md-12">
<div class="form-group">
<section class="row">
<div class="col-md-4">
<label for="carRegistration" class="form-label">Placa</label>
<input type="text" class="form-control" name="carRegistration" placeholder="CDE001" maxlength="6">
</div>
<div class="col-md-4">
<label for="name" class="form-label">Nombre</label>
<input type="text" class="form-control" name="name" placeholder="Ferrari Enzo">
</div>
<div class="col-md-4">
<label for="fromProduction" class="form-label">Planta Produccion</label>
<input type="text" class="form-control" name="fromProduction" placeholder="Bmw sede1">
</div>
</section>
<section class="row mt-4">
<div class="col-md-4">
<label for="placa" class="form-label">Fecha Ensamble</label>
<input type="date" class="form-control" name="dateAssembled" placeholder="CDE001">
</div>
<div class="col-md-4">
<label for="model" class="form-label">Módelo Matricula</label>
<input type="text" class="form-control" name="model" maxlength="4" placeholder="2013">
</div>
<div class="col-md-4">
<label for="stateStored" class="form-label">Ciudad Almacenamiento</label>
<Select type="text" class="form-control" id="stateStored" placeholder="Medellin">
<option value=''>Elija una opción</option>
<option value='Medellin'>Medellín</option>
<option value="Bucaramanga">Bucaramanga</option>
<option value="Cali">Cali</option>
<option value="Bogota">Bogotá</option>
</Select>
</div>
</section>
</div>
</section>
</div>
<button type="submit" class="btn btn-success mt-4">Guardar</button>
</form>
</div>
The problem is from your template. The select tag should have a name attribute.
Change your template to this
$car->dateAssembled = $request->dateAssembled;
$car-> save();
return redirect()->route('cars')->with('success','Registro guardado satisfactoriamente');
}}
Template:
#extends('header')
#section('content')
<div class="container w-10 mt-5 border p-4">
<form action="{{ route('cars') }}" method="POST">
#csrf
#if (session('success'))
<h6 class="alert alert-success">{{ session('success') }}</h6>
#endif
#error('carRegistration')
<h6 class="alert alert-danger">{{ $message }}</h6>
#enderror
<p class="h2">Registro vehiculos</p>
<br>
<div class="row">
<section class="col-md-12">
<div class="form-group">
<section class="row">
<div class="col-md-4">
<label for="carRegistration" class="form-label">Placa</label>
<input type="text" class="form-control" name="carRegistration" placeholder="CDE001" maxlength="6">
</div>
<div class="col-md-4">
<label for="name" class="form-label">Nombre</label>
<input type="text" class="form-control" name="name" placeholder="Ferrari Enzo">
</div>
<div class="col-md-4">
<label for="fromProduction" class="form-label">Planta Produccion</label>
<input type="text" class="form-control" name="fromProduction" placeholder="Bmw sede1">
</div>
</section>
<section class="row mt-4">
<div class="col-md-4">
<label for="placa" class="form-label">Fecha Ensamble</label>
<input type="date" class="form-control" name="dateAssembled" placeholder="CDE001">
</div>
<div class="col-md-4">
<label for="model" class="form-label">Módelo Matricula</label>
<input type="text" class="form-control" name="model" maxlength="4" placeholder="2013">
</div>
<div class="col-md-4">
<label for="stateStored" class="form-label">Ciudad Almacenamiento</label>
<Select type="text" name="stateStored" class="form-control" id="stateStored" placeholder="Medellin">
<option value=''>Elija una opción</option>
<option value='Medellin'>Medellín</option>
<option value="Bucaramanga">Bucaramanga</option>
<option value="Cali">Cali</option>
<option value="Bogota">Bogotá</option>
</Select>
</div>
</section>
</div>
</section>
</div>
<button type="submit" class="btn btn-success mt-4">Guardar</button>
</form>
</div>
Thanks for help, the error come from because I call from name on the controller and in this input only have ID, and in the validation for this field have 'required';
I don't know how reply comments, but thanks aynber and Daniel L, you were nice help
First time Comment your validation section and try again. If your data successfully inserted. Then Your need to modify your required field like below.
Replace
['required','min:6']
Like this:
'required|min:6',
I am very confused that my html form action doesn't redirect me to another page, because this has always worked.
Here's my code
<section class="contact section-padding" data-scroll-index="6">
<div class="container">
<div class="row">
<div class="section-head text-center col-sm-12">
<h4>Neem contact op</h4>
<h6>Vul formulier in</h6>
</div>
<div class="offset-lg-2 col-lg-8 offset-md-1 col-md-10">
<form method="post" class="form" id="contact-form" action="verstuurd.php">
<div class="messages"></div>
<div class="controls">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input id="form_name" type="text" name="volledige_naam" placeholder="Volledige naam">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input id="form_email" type="email" name="email" placeholder="E-mailadres" >
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<input id="form_subject" type="text" name="subject" placeholder="Onderwerp">
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<textarea id="form_message" name="message" placeholder="Bericht" rows="4" ></textarea>
</div>
</div>
<div class="col-md-12 text-center">
<button type="submit"><span>Verstuur</span></button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</section>
What is wrong with this? I thought it might has to do something with the div classes, but is this possible?
Edit
Verstuurd.php
<section class="contact section-padding" data-scroll-index="6">
<div class="container">
<div class="row">
<div class="section-head text-center col-sm-12">
<h4>Succesvol verstuurd</h4>
<h6>We nemen zo snel mogelijk contact met u op</h6>
</div>
</div>
</div>
</section>
At the moment I do not have any php code in verstuurd.php. I thought that aciton only redirects to PHP files and not HTML files.
I'm guessing there's some javascript that is blocking the form submission. Look out for anything similar to e.preventDefault(); in relation to form submission.
Change your button from
<button type="submit"><span>Verstuur</span></button>
to
<input id="submit" name="submit" type="submit" value="Verstuur">
So i have a controller with a basic search function and i want to know when a user click the search button if there is data exist i want it to return the same page with error message, but if data not exist i want return another page. how can i do that? my code as below:
controller:
public function search(Request $request, $companyID, $entityType)
{
$data = [];
$intentTypes = DiraQuestion::select('intent')->where('company_id', $companyID)->groupBy('intent')->get();
foreach ($intentTypes as $intent)
{
$data[$intent->intent] = $intent->intent;
}
$q = $request->q;
$user = DiraQuestion::select('eVal')->where('company_id', $companyID)->where('eType', $entityType)->where('eVal','LIKE','%'.$q.'%')->groupBy('eVal')->get();
return view('AltHr.Chatbot.addType', compact('data','entityType','companyID'))->withDetails($user)->withQuery($q);
}
my current view page which shows if exist and if not exist shows form:
#if(isset($details))
<div class="container-fluid container-fixed-lg">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<!-- <div class="panel-heading">
<div class="panel-title"><b>{{ $query }}</b></div>
<div class="clearfix"></div>
</div> -->
<div class="panel-body">
<div class="form-group edit-response-container">
<div class="col-md-12">
#foreach($details as $user)
<p><span style="color:red;">{{$user->eVal}}</span> is already included!</p>
#endforeach
</div>
#if($details->isEmpty())
<form action="{{action('AltHr\Chatbot\ChatbotController#addQType', [$companyID, $entityType])}}" method="post">
{{csrf_field()}}
<!-- #if(empty($data))
<p>No predefined intents.</p>
#else -->
<div class="col-md-12">
<div class="form-group form-group-default required">
<label>New Type</label>
<input type="text" class="form-control" name="entityValue" placeholder="{{$query}}" value="{{$query}}" required readonly/>
</div>
</div>
<!-- <div class="col-md-12">
<div class="form-group form-group-default required">
<label>New Question</label>
<input type="text" class="form-control" name="question" placeholder="Enter Sample Question" required>
</div>
</div>
<div class="col-md-12">
<div class="form-group form-group-default required">
<label>Intent</label>
<select class="full-width" name="intent" data-init-plugin="select2" required>
<option selected disabled></option>
#foreach($data as $datas)
<option value="{{$datas}}">{{$datas}}</option>
#endforeach
</select>
</div>
</div> -->
<div class="col-md-12">
<div class="new-field">
<div class="form-group-attached">
<div class="form-group form-group-default required">
<label>Synonyms:</label>
<input type="text" class="form-control" name="syn" placeholder="Enter Synonyms" />
</div>
</div>
</div>
<p><i>*Enter All Synonyms Separating With ','</i></p>
</div>
<div class="col-md-12">
<br>
<!-- <button type="button" class="btn alt-btn-green alt-btn btn-xs add-new">Add Synonym</button> -->
<button type="submit" class="btn alt-btn-green alt-btn btn-xs">Save</button>
test
</div>
#endif
</form>
#endif
</div>
</div>
</div>
</div>
</div>
</div>
#endif
route:
Route::post('search/{companyID}/{entityType}','Chatbot\ChatbotController#search');
as you can see currently if data exist, it shows error message on the same page, but if no data it shows a form on the same page itself.. i want it to route to another page when there is no data found.
If you want to include another snippet inside of your #if then you can do so like this:
#include('route.to.view')
Which will search for the blade view in that url and insert the html in case when there is $data present
i was trying to display news with its comments, but one of the headlines is giving me an error,but others are working, i have a table of news and i have a table of news_comments, some of the news are being retrieved perfectly with their comments but this one is giving me an error.
#extends('layouts.app')
#section('content')
<div class="container">
{{$news->title}}<br/>
#foreach($news->news_pictures as $news_picture)
<img src="{{asset($news_picture->pictures)}}" width="200"><br/>
#endforeach
{!! $news->body !!} <br/>
<small>written on{{$news->created_at}} by {{$news->user->name}} </small>
</div>
#foreach($news->news_comments as $news_comment)
#if(!Auth::guest())
<div class="well">
{!! $news_comment->user->name!!}
{{$news_comment->comments}}<br/>
{{$news_comment->created_at}}
</div>
#else
<div class="well">
{{$news_comment->commentor}}<br/>
{{$news_comment->comments}}<br/>
{{$news_comment->created_at}}
</div>
#endif
#endforeach
#if(!Auth::guest())
<form action="{{action('NewsController#AddComments',[$news->id])}}" method="post">
{{csrf_field()}}
<div class="container">
<textarea type="text" class="form-control" name="comments" placeholder="your comment"></textarea>
<button class="btn btn-primary" >post</button>
</div>
</form>
#else
<form action="{{action('NewsController#AddComments',[$news->id])}}" method="post">
{{csrf_field()}}
<div class="container">
<input type="text" class="form-control" placeholder="your name" name="commentor">
<textarea type="text" class="form-control" name="comments" placeholder="your comment"></textarea>
<button class="btn btn-primary" >post</button>
</div>
</form>
#endif
#endsection
This error occur when the property you want to access that doesn't exist so you should check property isset or not
Here is the example
#if (!is_null($news_comment->user))
<div class="well">
{!! $news_comment->user->name!!}
{{$news_comment->comments}}<br/>
{{$news_comment->created_at}}
</div>
#endif
OR
#if (isset($news_comment->user->id) && isset($news_comment->user->name))
<div class="well">
{!! $news_comment->user->name!!}
{{$news_comment->comments}}<br/>
{{$news_comment->created_at}}
</div>
#endif
Try to use: with () on user
{!! $news_comment->user()->name!!}
Instead of:
{!! $news_comment->user->name!!}
I am doing project in laravel 5.2, for report creation in "vehicleDetail.blade.php" i need to give one drop down option, in that i need to get vehicle names which are there in the database. From that list if i select one vehicle, select fromDate , toDate and then click on generate report i should be able to fetch data from the database (device table). For this filter engine how can i make the drop down list byb fetching data fro the database?
vehicleDetail.blade.php
#extends('app')
#section('content')
<br><br><br><br><br>
<div class="templatemo-content-wrapper">
<div class="container">
<ol class="breadcrumb">
<li><font color="green">Home</font></li>
<li class="active">Vehicle Detail</li>
</ol>
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-success">
<div class="panel-heading">Vehicle Detail</div>
<div class="panel-body">
#if (count($errors) > 0)
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<form class="form-horizontal" role="form" method="POST" action="{{ url('group/update/') }}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group">
<label class="col-md-4 control-label">Vehicle</label>
<div class="col-md-6">
<input type="text" class="form-control" name="groupID" value="{{ ('#')}}">
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">From Date</label>
<div class="col-md-6">
<input type="date" class="form-control" name="Fdate">
</div>
<label class="col-md-4 control-label">To Date</label>
<div class="col-md-6">
<input type="date" class="form-control" name="Tdate" >
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-warning">
Get Report
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
Any one please help me to do this, response are appreciable.
In your controller get all values from database in a variable like:
$list = DB::table('tablename')->get(array('id', 'name'));
and pass it on view like:
return view('viewname', array('list' => $list));
Now use it on view like:
foreach($list as $key => $val)
{
//drop down html here
}