This is a form to create a new scorecard.. When I click on add new objective button. A new objective is added. My problem comes when I want to add new kpi in the second or other objectives apart from the firt one, the kpi is added in the first objective and also it adds the whole scorecard form instead of only one objective per click.This image shows how the kpi is added.
Here is my scorecard code
<form id="form" action='/scorecard'>
<div class="class" id="objectives_place">
<div class="row col-md-10 col-md-offset-1" >
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label for="name">Name</label>
<input id="scoreCardName" name="scoreCardName" value="{{ $scorecard['name'] }}" style="height: 40px;" type="text" class="form-control" placeholder="score card name" required>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="name">Employee</label>
<select name="employeeid" id="employeeid" class="form-control" style="height: 40px;">
<option value="">choose employee</option>
#foreach($employees as $employee)
<option value="{{$employee->id}}"
#if(($employee->id) == (isset($scorecard_info->employee_id)?$scorecard_info->employee_id:''))
selected
#endif>{{$employee->first_name}} {{$employee->middle_name}} {{$employee->lastname}}
</option>
#endforeach
</select>
<br>
{{-- <small>Select Employee for the Objective Button to appear</small> --}}
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="description">Description</label>
<textarea name="scorecard_description" class="form-control" id="description" style="resize: none;height: 40px;" placeholder="score card description">{{ $scorecard['description'] }}</textarea>
</div>
</div>
</div>
<div id="objectivesData" class="row ">
#include('organization::objectiveAdd')
</div>
</div>
</div>
<div class="row col-md-10 col-md-offset-1">
<div class="row col-md-12">
<button id="newobjectivebtn" type="button" style="width:200px; float: left; padding: 5px;background-color:#a3d84e; border: 1px solid #fff; color: #fff; display: none;">Add new Objective</button>
</div>
<div class="row col-md-12 text-center" ><br>
<div id="listobjective" style="max-height:400px;">
</div> <br>
<button type="button" id="savescorecard" style="width: 365px; padding: 5px;
background-color:#a3d84e; border: 1px solid #fff; color: #fff; display: none; float:right;">Save Scorecard</button>
</div>
</form>
This is jquery for adding new objective
$('#newobjectivebtn').click(function(){
var objectiveIndex = $(this).data("objective-index");
let form = $('form');
$.ajax({
headers:{
'X-CSRF-TOKEN':$('meta[name="csrf-token"]').attr('content')
},
type:'POST',
url:'{{route('add_scorecard_objectives')}}',
data:form.serialize(),
success:function(response){
var div = $('#objectivesData')
div.append(response);
},
error:function(response){
toastr.error('System Error , Contact Administrator!');
}
})
});
This is the jquery code for adding new kpi
$('#objectivesData').on('click','.newkpibtnn',function(){
let form = $('form');
var objectiveIndex = $(this).data("objective-index");
console.log(objectiveIndex);
$.ajax({
headers:{
'X-CSRF-TOKEN':$('meta[name="csrf-token"]').attr('content')
},
type: "POST",
url: "{{ route('add_objectives_kpis') }}",
data:form.serialize() + "&objectiveIndex=" + objectiveIndex,
success: function(response) {
var div = $('#kpis_row_data')
div.append(response);
},
error: function(error) {
console.log(error);
}
});
});
This is the objectiveAdd.blade.php file
#foreach ($scorecard['objectives'] as $objective)
<div class="row">
<div class="row col-md-12 " id="objectives_page">
<div class="container-fluid spark-screen">
<div class="row">
<div class="box box-green">
<div class="box-header with-border">
<h2 style="font-size: 22px;margin-bottom: -5px;margin-top: 0px; text-align:center;">Scorecard Objective</h2>
</div>
<div class="box-body" >
<div class="row col-md-10 col-md-offset-1">
<div class="row">
<div class="col-md-4">
<div class="form-group col-ms-12">
<label for="Objective">Name</label>
<input type="text" name="objectives[name]" value="{{ isset($objective['name'])?$objective['name']:'' }}" class="form-control" style="margin-bottom: 0px;" placeholder="objective name" />
<small id="error_objectivename" class="hidden" style="color: red;margin-left: 1%;font-size: 13px;height:40px;">Enter a Objective Name</small>
</div>
</div>
<div class="col-md-3">
<div class="form-group col-sm-12">
<label for="description">Weight</label>
<input class="form-control" maxlength="2" value="{{ isset($objective['weight'])?$objective['weight']:'' }}" type="number" name="objectives[weight]" placeholder="%" min="1" max="100" style="margin-bottom: 1px;">
<small id="error_objectiveweight" class="hidden" style="color: red;margin-left: 1%;font-size: 13px;height:40px;">Add Weight</small>
</div>
</div>
<div class="col-md-4">
<div class="form-group col-sm-12">
<label for="description">Description</label>
<textarea name="objectives[description]" class="form-control" id="objectivedescription" style="resize: none;height:40px;" placeholder="enter descriprion">{{ isset($objective['description'])?$objective['description']:'' }}</textarea>
</div>
</div>
<div class="col-md-1">
<span class="badge badge-pill delete-form" style="color: red !important; background: transparent !important; height:50px; padding-left: 50px; padding-top:40px; padding-right:60px;cursor: pointer;">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
</span>
</div>
</div>
<div class="row" >
<div class="form-group col-md-11">
<table class="table table-bordered table-condensed" id="kpis_table" >
<thead>
<tr>
<th scope="col" class="width-25-per">KPI Name</th>
<th scope="col" class="width-25-per">Weight</th>
<th scope="col" class="width-20-per">Description</th>
<th scope="col" class="width-25-per">Expected Delivery</th>
<th scope="col" class="width-10-per">Goal</th>
<th scope="col" class="width-10-per"></th>
</tr>
</thead>
<tbody class="addKpis" id="kpis_row_data">
#include('organization::objectiveAddKpi')
</tbody>
</table>
</div>
</div>
</div>
<div class="row col-md-10 col-md-offset-1">
<div class="row col-md-12">
<button class="newkpibtnn" data-objective-index="{{ $index }}" type="button" style="width:200px; float: left; padding: 5px;background-color:#a3d84e; border: 1px solid #fff; color: #fff;">Add new KPI</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
#endforeach
My routes.php file
Route::post('/add_objective', 'OrganizationController#addScorecardObjective')->name('add_scorecard_objectives');
Route::post('/add_kpis', 'OrganizationController#addKpi')->name('add_objectives_kpis');
This is my controller
public function addScorecardObjective(Request $request)
{
$data = $request->all();
unset($data['expected_delivery_date']);
$data['objectives'] = array(['name'=>'','weight'=>'','description'=>'','kpis'=>[
['name'=>'','weight'=>'','description'=>'','expected_delivery_date'=>'','goal'=>'']
]]);
return view('organization::objectiveAdd')->with([
'scorecard'=>$data
]);
}
public function addKpi(Request $request)
{
$data = $request->all();
$objectiveIndex = $data['objectiveIndex'];
$data['objectives'] = array($data['objectives']);
$data['objectives'][$objectiveIndex]['kpis'] = array(['name'=>'','weight'=>'','description'=>'','expected_delivery_date'=>'','goal'=>'']);
return view('organization::objectiveAdd')->with([
'scorecard'=>$data
]);
}
I want to be able to add a number of kpis in a particular objective whenever I click on add new objective button on that particular objective.
Related
The caption explains it best. When I press the Submit button - the form should redirect to the Controller method "store" and execute the logic written. But instead, it just reloads the page. How do I know that the Controller isn't accessed? I have tried using dd() in the store() method and it never pops up.
Following is the HTML/PHP:
#extends('admin.layout')
#section('content')
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="{{url('js/datatables/dataTables.bootstrap4.css')}}">
<div class="intro-y col-span-12 mt-4">
<!-- BEGIN: Vertical Form -->
<div class="intro-y box">
<div class="flex flex-col sm:flex-row items-center p-5 border-b border-slate-200/60 dark:border-darkmode-400">
<h2 class="font-medium text-base mr-auto">
Course Cover
</h2>
</div>
<form action="{{ route('course.store') }}" method="post" enctype="multipart/form-data">
#csrf
#method('POST')
<div id="vertical-form" class="p-5">
<div class="preview">
<div class="avatar-upload" style="margin: 0 !important; max-width: 485px;">
<div class="avatar-edit" style="top:-20px !important; /* position: relative !important; */">
<input type='file' name="cover" id="imageUpload" accept=".png, .jpg, .jpeg" />
<label for="imageUpload"><i data-lucide="pen-tool" style="color: #232d45 !important;padding: 3px;left: 4px;top: 4px;position: relative;"></i></label>
</div>
<div id="imagePreview" style="background-size: cover; background-position: center; box-shadow: rgb(0 0 0 / 10%) 0px 2px 4px 0px; border: 1px solid rgb(141 146 157); margin: 0; border-radius: 11px; width: 452.66px !important; height: 224px; background-image: url(https://www.ysm.ca/wp-content/uploads/2020/02/default-avatar.jpg);">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="intro-y col-span-12 mt-4">
<!-- BEGIN: Vertical Form -->
<div class="intro-y box">
<div class="flex flex-col sm:flex-row items-center p-5 border-b border-slate-200/60 dark:border-darkmode-400">
<h2 class="font-medium text-base mr-auto">
Course Details
</h2>
</div>
<div id="vertical-form" class="p-5">
<div class="grid grid-cols-12 gap-2 mt-4 mb-4">
<label for="vertical-form-1" class="form-label col-span-6">Course Title</label>
<label for="vertical-form-1" class="form-label col-span-6">Course Difficulty</label>
<input type="text" name="name" placeholder="Name.." class="form-control col-span-6" placeholder="Input inline 1" aria-label="default input inline 1">
<select name="difficulty" class="form-select form-select col-span-6" aria-label="Select Course Difficulty">
<option value="Beginner">Beginner</option>
<option value="Intermediate">Intermediate</option>
<option value="Expert">Expert</option>
</select>
</div>
<div class="mt-4 mb-4">
<label for="vertical-form-1" class="form-label">Categories</label>
<select name="categories[]" data-placeholder="Choose appropriate categories for this course.." class="tom-select w-full" multiple>
#foreach ($categories as $category)
<option value="{{ $category->id }}">{{ $category->name }}</option>
#endforeach
</select>
</div>
</div>
</div>
</div>
<div class="intro-y col-span-12 mt-4">
<!-- BEGIN: Vertical Form -->
<div class="intro-y box">
<div class="flex flex-col sm:flex-row items-center p-5 border-b border-slate-200/60 dark:border-darkmode-400">
<h2 class="font-medium text-base mr-auto">
Course Description
</h2>
</div>
<div id="vertical-form" class="p-5">
<div class="mt-4 mb-4">
<textarea class="dark:border-darkmode-400"" cols="80" id="editor2" name="description" rows="10" data-sample-short>Type a detailed description of the course i.e its prerequisites, requirements, learning outcome and any other details that may be needed.</textarea>
</div>
</div>
</div>
</div>
<div class="intro-y col-span-12 mt-4">
<!-- BEGIN: Vertical Form -->
<div class="intro-y box">
<div class="flex flex-col sm:flex-row items-center p-5 border-b border-slate-200/60 dark:border-darkmode-400">
<h2 class="font-medium text-base mr-auto">
Choose Instructor
</h2>
</div>
<div id="vertical-form" class="p-5">
<table class="table table-responsive table-striped table-vcenter js-dataTable-full">
<thead>
<tr>
<th class="text-center">PICK</th>
<th>ID</th>
<th>AVATAR</th>
<th class="d-none d-sm-table-cell">NAME</th>
<th class="d-none d-sm-table-cell" style="width: 15%;">EMAIL</th>
<th class="text-center" style="width: 15%;">Profile</th>
</tr>
</thead>
<tbody>
#foreach ($teachers as $teacher)
<tr>
<td class="w-10">
<input class="form-check-input" type="radio" name="teacher_id" value="{{ $teacher->id }}">
</td>
<td class="w-10">{{ $teacher->id }}</td>
<td class="w-20">
<div class="w-10 h-10 image-fit zoom-in ml-2">
<img class="rounded-full" src="{{ url('images/'.$teacher->avatar) }}" alt="">
</div>
</td>
<td class="d-none d-sm-table-cell">{{ $teacher->name }}</td>
<td class="d-none d-sm-table-cell">
<span class="badge badge-danger">{{ $teacher->email }}</span>
</td>
<td class="text-center">
<button type="button" class="btn btn-sm btn-secondary" data-toggle="tooltip" title="View Customer">
<i class="fa fa-user"></i>
</button>
</td>
</tr>
#endforeach
</tbody>
</table>
<button type="submit" class="btn btn-primary mt-5">Create Course</button>
</form>
</div>
</div>
</div>
<script src="https://cdn.ckeditor.com/4.19.0/standard-all/ckeditor.js"></script>
<script defer src="https://use.fontawesome.com/releases/v5.15.4/js/all.js" integrity="sha384-rOA1PnstxnOBLzCLMcre8ybwbTmemjzdNlILg8O7z1lUkLXozs4DHonlDtnE7fpc" crossorigin="anonymous"></script>
<script>
CKEDITOR.replace('editor2', {
height: 260,
/* Default CKEditor 4 styles are included as well to avoid copying default styles. */
contentsCss: [
'http://cdn.ckeditor.com/4.19.0/full-all/contents.css',
'https://ckeditor.com/docs/ckeditor4/4.19.0/examples/assets/css/classic.css'
],
removeButtons: 'PasteFromWord',
});
</script>
<script>
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
$('#imagePreview').css('background-image', 'url('+e.target.result +')');
$('#imagePreview').hide();
$('#imagePreview').fadeIn(650);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#imageUpload").change(function() {
readURL(this);
});
</script>
<script src="{{url('js/datatables/jquery.dataTables.min.js')}}"></script>
<script src="{{url('js/datatables/dataTables.bootstrap4.min.js')}}"></script>
<script src="{{url('js/be_tables_datatables.min.js')}}"></script>
#endsection
What am I doing wrong here? Why is the form not taking me to course.store method in the CourseController? And the controller is a resource controller. So the routing is very straight-forward, and not an issue in this case either.
I think you need to check your closing div tags, you must not close a div that is the parent of the form before closing the form tag,
May be you Forgot to remove Last Div tage and also you should write at last #endsection
#extends('admin.layout')
#section('content')
//here you can write your form as well as other HTML
#endsection
I had the same issue, in my case the problem was registered the same Route
Route::post('/users', [UserController::class, 'store']);
Route::post('/users', [UserController::class, 'storeDashboard']);
I wanted to fire store method but storeDashboard was firing instead
I have created a controller, model and view for the Profile menu, but when I try to update my own profile, the data cannot be updated and the ERROR message is not found.
this is the ProfileController.php file:
enter code here
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Auth;
use App\Profile;
class ProfileController extends Controller
{
public function edit($id)
{
return view('profile.profile',compact('id'));
}
public function update(Request $request, $id)
{
$profile = Profile::find($id)->first();
$this->validate($request, [
"name" => 'required|string',
"email" => 'required|email|unique:users',
"alamat" => 'required',
"nohp" => 'required',
"password" => 'required|confirmed|min:8',
]);
if ($request->has('password')){
$profile->name = $request->name;
$profile->email = $request->email;
$profile->alamat = $request->alamat;
$profile->nohp = $request->nohp;
$profile->password = bcrypt($request->password);
}
else{
$profile->name = $request->name;
$profile->email = $request->email;
$profile->alamat = $request->alamat;
$profile->nohp = $request->nohp;
}
$profile->save();
return redirect()->back();
}
this is the profile.php file:
enter code here
#extends('layouts.app')
#section('content')
<div class="container bg-white">
<!-- Content Header -->
<div class="content-header">
<!-- CARD PROFILE -->
<section class="content">
<div class="container-fluid">
<div class="col-md-12">
<div class="row">
<div class="col-md-4">
<div class="card card-warning" style="border-top-left-radius:40px; border-top-right-radius:40px;">
<div class="card-body box-profile" style="margin-top: 10px; margin-bottom: 10px;">
<img src="{{asset('adminlte/dist/img/user.png')}}" class="img-circle elevation-2" style="width:140px; height: 140px; margin-left: 85px; margin-bottom: 10px;" alt="User Image" align="center">
<h3 align="center"><strong>{{Auth::user()->name}}</strong></h3>
</div>
</div>
<div class="card card-warning" style="margin-top: 15px; border-radius:40px;">
<div class="card-header" style="background-image: linear-gradient(#40E0D0,#40E0D0);">
<h4 class="card-tittle" align="center"><strong>Tentang Saya</strong></h4>
</div>
<div class="card-body" style="font-family:glacial-indiference;">
<strong><img src="{{asset('adminlte/dist/img/email.png')}}" style="width:30px; height: 30px; margin-left: 7px; margin-right: 4px"
> Email</strong>
<p class="text-muted" style="margin-left: 45px">{{Auth::user()->email}}</p>
<hr>
<strong><img src="{{asset('adminlte/dist/img/address.png')}}" style="width:30px; height: 30px; margin-left: 7px; margin-right: 4px"
> Alamat</strong>
<p class="text-muted" style="margin-left: 45px">{{Auth::user()->alamat}}</p>
<hr>
<strong><img src="{{asset('adminlte/dist/img/phone.png')}}" style="width:30px; height: 30px; margin-left: 6px; margin-right: 6px"
> No. Telp</strong>
<p class="text-muted" style="margin-left: 45px">{{Auth::user()->nohp}}</p>
<hr>
</div>
</div>
</div>
<div class="col-md-8">
<div class="card col-md-12" style="border-top-right-radius:40px; border-bottom-left-radius:40px;">
<h4 class="card-tittle" align="center" style="margin-top:20px">
<strong>Edit Profile</strong>
</h4>
<form action="{{ route('profile.profile', $id) }}" method="post" enctype="multipart/form-data" style="width:95%; margin-left:16px"> #method('patch')
#csrf
<div class="form-group">
<label for="name">Nama</label>
<input type="text" class="form-control" name="name" value="{{Auth::user()->name}}" required>
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="text" class="form-control" name="email" value="{{Auth::user()->email}}" required>
</div>
<div class="form-group">
<label for="alamat">Alamat</label>
<input type="text" class="form-control" name="alamat" value="{{Auth::user()->alamat}}" required>
</div>
<div class="form-group">
<label for="nohp">NoHP</label>
<input type="text" class="form-control" name="nohp" value="{{Auth::user()->nohp}}" required>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" name="password">
<label>*) Jika Password tidak diganti, kosongkan saja.</label>
</div>
<div class="form-group" align="center" style="margin-top: 30px; margin-bottom: 30px;">
<button type="submit" class="btn btn-block" style=" border-radius:30px; background-image: linear-gradient(#40E0D0,#40E0D0); width:60%; height:20%"
>Perbaharui</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
#endsection
enter code here
when run, the result will be like this:
data before updating
the data after being replaced and the results are back as before:
the data after being replaced and the results are back as before
I don't know where the error is because there is no ERROR message.
I need your help to solve this problem
You are not updating the record you are trying to find by 'id'. Profile::find($id)->first(); is finding the record with the primary key $id and then doing a new query to get the "first" record from the table. So $profile is not the record you are trying to find by 'id'; you are updating the wrong record (the same wrong record) every time.
$profile = Profile::findOrFail($id);
We will use findOrFail to not have to deal with any null being returned if it can't find a record.
On a side note, the if/else could use some cleaning:
if ($request->has('password')) {
$profile->password = bcrypt($request->password);
}
$profile->name = $request->name;
...
I want to get the information from this formwhen you press the add to cart button. and i want to use that information in a cart page.
<?php
$result = mysqli_query($conn,$query);
$output = '';
while($row = mysqli_fetch_assoc($result)) {
$output .= '
<div style="margin-bottom: 20px;" class="col-lg-3 col-md-6 col-sm-6">
<form method="post ">
<div style="height: 400px;" class="card shadow text-center">
<div class="card-block shop-item">
<img class="shop-item-image" src="Bilder/clothes/'. $row['ProductImage'].'" alt="" class="img-fluid" style="height: 200px;">
<div class="card-text shop-item-title">
'.$row['Brand'].'
</div>
<div class="card-text">
'.$row['Quantity'].' in stock
</div>
<div class="shop-item-details">
<div class="card-text" shop-item-price>
<h3>£ '.$row['Price'].'</h3>
</div>
<input style="width: 80%; margin-left: 10%; " type="text" name="quantity" class="form-control" value="1"/>
<button style="margin-top: 10px; margin-bottom: 10px; background-color:#FB8122; border: none; color:black;"href="#" class="shop-item-button btn btn-primary ">Add to cart <span class="fas fa-cart-arrow-down"></span></button>
</div>
</div>
</div>
</form>
</div>;';
}
echo $output;
}
?>
First time asking so sorry if I did something wrong
I have 1 main form. I also have a sub form inside that main form.
I can't seem to prevent the main form to stop submitting since the button type submit will submit the main form automatically.
Form UI
When I click on delete the modal slide up with 2 options
When I click on DELETE, I only one to submit to delete image that's it.
edit.blade.php
#extends('layouts.be.master')
#section('content')
<script type="text/javascript" src="/js/ckeditor.js"></script>
<link rel="stylesheet" type="text/css" href="http://d.biossusa.com/css/root/hover-master/hover.css">
<style type="text/css">
.portfolio-images {
border: solid 1px silver;
}
._hover{
padding: 0px;
position: relative;
overflow: hidden;
border: 1px solid #D8D8D8;
/*border-radius: 10px;*/
}
._hover:hover .caption{
opacity: 1;
transform: translateY(-150px);
-webkit-transform:translateY(-150px);
-moz-transform:translateY(-150px);
-ms-transform:translateY(-150px);
-o-transform:translateY(-150px);
}
._hover img{
z-index: 4;
}
._hover .caption{
position: absolute;
top:150px;
-webkit-transition:all 0.3s ease-in-out;
-moz-transition:all 0.3s ease-in-out;
-o-transition:all 0.3s ease-in-out;
-ms-transition:all 0.3s ease-in-out;
transition:all 0.3s ease-in-out;
width: 100%;
}
._hover .blur{
background-color: rgba(0,0,0,0.8);
height: 300px;
z-index: 5;
position: absolute;
width: 100%;
}
._hover .caption-text{
z-index: 10;
color: #fff;
position: absolute;
height: 300px;
text-align: center;
top:-20px;
width: 100%;
}
</style>
<?php $tags = explode(",", $portfolio->tag ); ?>
<div class="card-body card-padding">
<div class="row">
{!! Form::open(array('class' => 'form-horizontal', 'role' =>'form', 'url'=>'portfolio/'. $portfolio->id .'/update','files' => true)) !!}
<div class="col-sm-12">
{{-- Name --}}
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" value="{{ $portfolio->name }}" name="name" class="form-control" id="name" placeholder="Name">
</div>
</div>
{{-- Type --}}
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Type</label>
<div class="col-sm-10">
<select name="type" class="form-control">
#foreach($portfolioTypes as $item)
<option value="{{ $item }}">{{ $item }}</option>
#endforeach
</select>
</div>
</div>
{{-- Tags --}}
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Tags</label>
<div class="col-sm-10">
</div>
<input id="tags" name="tag">
</div>
{{-- URL --}}
<div class="form-group">
<label for="url" class="col-sm-2 control-label">URL</label>
<div class="col-sm-10">
<input name="url" type="text" value="{{ $portfolio->url }}" class="form-control" placeholder="URL">
</div>
</div>
{{-- Images --}}
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Images</label>
#foreach($images as $image)
<?php
$crop_img = str_replace('full.jpg','crop.jpg',$image->img_path);
?>
<div class="col-sm-2">
<div class="_hover " style="background: transparent;">
<p style="text-align:center;">
<img class="img-responsive" src="{{ $image->image_path }}" alt="">
</p>
<div class="caption">
<div class="blur"></div>
<div class="caption-text">
<h6 class="title lighter" style="padding:5px;border-radius: 10px;">
{{ $image->id }}
</h6>
<p>
<span>
<a data-toggle="modal" data-target="#delete_image_{{ $image->id or '' }}">
delete
</a>
</span>
</p>
</div>
</div>
</div>
</div>
<div class="modal fade" id="delete_image_{{ $image->id }}">
<div class="model-content" style="margin-top: 200px;">
<div class="col-sm-offset-4 col-sm-4 ">
{!! Form::model($image, array( 'url' => '/portfolio/image/'.$image->id.'/destroy','method' => 'DELETE')) !!}
<button type="submit" class="btn btn-danger btn-lg btn-block">Delete ({{ $image->id }})</button>
<a class="btn btn-primary btn-lg btn-block" data-dismiss="modal" > Cancel </a>
{!! Form::hidden('$id', $image->id)!!}
{!! Form::close()!!}
</div>
</div>
</div>
#endforeach
<br><br>
<input id="images" name="images[]" type="file" multiple>
</div>
{{-- Description --}}
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Description</label>
<div class="col-sm-10">
<textarea name="description" rows="20" cols="80" id="description">
{{ base64_decode($portfolio->description) }}
</textarea>
<script>
CKEDITOR.replace( 'description' );
</script>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-4 col-sm-8">
<a class="btn btn-default" href="/portfolio"> Cancel </a>
<button type="submit" class="btn btn-info">Done</button>
</div>
</div>
</div>
{!!Form::close()!!}
</div>
</div>
#stop
#section('custom-scripts')
<link rel="stylesheet" type="text/css" href="/css/jquery.tag-editor.css">
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="https://code.jquery.com/ui/1.10.2/jquery-ui.min.js"></script>
<script type="text/javascript" src="/js/jquery.caret.min.js"></script>
<script type="text/javascript" src="/js/jquery.tag-editor.js"></script>
<script type="text/javascript">
$( "select[name*='type']" ).val("{{ $portfolio->type }}");
function readLogo(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#portfolio-icon').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$( "input[name*='logo_path']" ).change(function(){
readLogo(this);
});
$('#tags').tagEditor({
autocomplete: {
delay: 0,
position: { collision: 'flip' },
source: [<?php echo '"'.implode('","', $skillList).'"' ?>]
},
forceLowercase: false,
delimiter: ',', /* space and comma */
placeholder: 'Enter tags ...',
initialTags: [<?php echo '"'.implode('","', $tags).'"' ?>]
});
</script>
#stop
How would one go about debugging this further?
My goal is to stay with HTML, blade and Laravel as much as possible to solve this problem.
May be Use to someone
$('#formId').submit(function (event) {
event.preventDefault();
});
It is invalid html to have a form inside a form.
I'd try to place the modal outside the main form.
I would make hidden form outside of the original form and then send it with button that has form attribute. That "form" is valid html5 attribute.
<button type="submit" form="id_of_form_to_submit" value="Submit">Submit</button>
Here you can find more information:
https://www.w3schools.com/Tags/att_button_form.asp
I am new to Laravel and I am creating content management system as practice to get familiar with the framework. Currently, I am working on the feature for the user to preview the information they have entered for updating the new page they want to create and here is code for the view:
<div ng-controller="PagesController">
<form action="{{url('admin/page/preview')}}" method="post" name="pageForm">
<div class="col-md-9">
<div class="panel-body">
<div class="row">
<div class="form-group">
<label>Title</label>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="text" class="form-control input-md" name="title" ng-model="page.title">
</div>
<!-- <input type="submit" value="Preview"> -->
</div>
<div class="row">
<div class="form-group">
<fieldset style="border: 1px solid #E4E4E4; padding-top: 5px; padding-bottom: 5px;">
<div class="form-group">
<div class="col-md-5">
<label>Add File</label>
<input type="file" name="upload" nv-file-select uploader="updateUploader" value="Select Picture" ng-model="page.upload" >
</div>
<div class="col-md-6">
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Progress</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in updateUploader.queue">
<td style="max-width: 170px; word-wrap: break-word;" ng-cloak><strong>#{{ item.file.name}}</strong></td>
<td><div class="col-md-12"><progressbar value="item.progress"></progressbar></div></td>
<td nowrap ng-cloak>
<button type="button" class="btn btn-danger btn-xs" ng-click="item.remove()">
<span class="glyphicon glyphicon-trash"></span> Remove
</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</fieldset>
</div>
</div><br>
<div class="row">
<div class="form-group">
<label>Body</label>
<input type="hidden" name="body" value="#{{page.body}}"/>
<summernote name="body" ng-model="page.body" config="options" height="300"></summernote>
<div ng-messages="pageForm.body.$error" ng-if="pageForm.body.$dirty">
<div ng-message="required">
<span class="error-msgs">Please enter page information</span>
</div>
</div>
</div>
</div>
<br/>
<div class="row">
<div class="form-group">
<div class="col-md-12 text-left">
</div>
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="checkbox col-md-12 text-left">
<label><input type="checkbox" value="" ng-model"page.serivice" ng-false-value="0" ng-true-value="1" ><strong>Update page to services</strong></label>
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-md-12 text-left">
<button type="button" class="btn btn-success" name="update" ng-disabled="pageForm.$invalid" ng-click="update()">Update</button>
<input type="submit" class="btn btn-default btn-md" value="Preview">
</div>
</div>
</div>
</div>
<div class="col-md-3">
<div class="panel panel-default general-panel publish" style="margin-top: 35px;">
<div class="panel-heading">
<div class="title">Navigation</div>
</div>
<div class="panel-body">
<span class="">
<i></i><strong>Parent pages</strong>
<div class="btn-group">
<select class="form-control" name="publish_period" ng-model="page.parent_nav">
<option value="">No Parent Navigation</option>
<option value="about-us">About Us</option>
<option value="media">Media</option>
<option value="publication">Publication</option>
<option value="law">Law</option>
<option value="legislation">Legislation</option>
<option value="compliance">Compliance</option>
<option value="license">Applying For License</option>
</select>
</div><br><br>
</span>
</div>
</div>
<div class="panel panel-default general-panel general-summary">
<div class="panel-body">
<table class="table">
<thead>
<tr>
<th colspan="3"><h5>Uploaded Documents</h5></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="document in documents">
<td style="max-width: 100px; word-wrap: break-word;">#{{document.file_path}}</td>
<td>
<i class="fa fa-download fa-fw"></i>Download
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</form>
</div>
Here is the code for the route for previewing the page:
Route::post('page/preview','PagesController#preview');
and the controller method for the preview function:
public function preview(Request $request)
{
return view('admin.pages.preview')->with('title',$request->input('title'))->with('body',$request->input('body'));
}
This works for me, but when I refreshed the preview page it would generate an error saying BadMethodCallException. So I am wondering how can eliminate this from happening? and thanks in advance.