print result after submitting in laravel - laravel

how can I create a submit button that can show the pdf result of my form to print it directly?
this is my code below
<form method="post" action="{{ url('dashboard/generate') }}" enctype="multipart/form-data" id="form-ui">
{{ csrf_field() }}
<div class="col-md-6 col-xs-12">
<label for="exampleInputEmail1">Distributor</label>
<select name="distributor" id="type" class="form-control">
<option value="">Choose Distributor</option>
#foreach ($distributor as $item)
<option value="{{ $item->id }}">{{ $item->name }}</option>
#endforeach
</select>
</div>
<div class="col-md-6 col-xs-12">
<label for="exampleInputEmail1">Select Event</label>
<select name="event" id="type" class="form-control">
<option value="">Choose Event</option>
#foreach ($event as $item)
<option value="{{ $item->id }}">({{ $item->events->date }}, {{ $item->time }}, {{ $item->events->stage }})-{{ $item->title }}</option>
#endforeach
</select>
</div>
<div class="col-md-12 col-xs-12" style="margin-top: 10px;">
<button class="btn btn-success" type="submit" onclick="myFunction()">SUBMIT</button>
</div>
</form>
<script>
function myFunction() {
window.print();
}
</script>
but it just print the current page (the form page). any advice i can try?

try this onsubmit jquery event
<div class="col-md-12 col-xs-12" style="margin-top: 10px;">
<button class="btn btn-success" type="submit" name="submit">SUBMIT</button>
</div>
<script>
$(document).ready(function(){
$('body').on('submit', '.formsubmit', function(e) {
alert(1);
});

Related

Error store data laravel when have image in pages

I am insert data product with images in dashboard, when I try to order the product I have error 404 not found and the URL showing value database in table like http://127.0.0.1:8000/shops/order/[%7B%22id%22:2,%22category_id%22:1,%22name_product%22:%22asdasd%22,%22harga%22:123123123,%22image%22:%22product-images//HapOzHmJPim1kIfmIeCM21xesCnIbR5Z7lpzcO8M.jpg%22,%22published_at%22:null,%22created_at%22:%222022-05-23T16:25:00.000000Z%22,%22updated_at%22:%222022-05-23T16:25:10.000000Z%22,%22kategori%22:%7B%22id%22:1,%22name_category%22:%22Top%22,%22created_at%22:%222022-05-23T16:22:40.000000Z%22,%22updated_at%22:%222022-05-23T16:22:40.000000Z%22%7D%7D].
But when I am insert data product without images in dashboard, and then I try to order the product is successful.
This is my route
Route::post('/shops/order/{shop:id}', [OrderController::class, 'store']);
This is OrderController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Order;
use App\Models\User;
use App\Models\Shop;
class OrderController extends Controller
{
public function store(Request $request)
{
$createOrder = $request->validate([
'user_id' => 'required',
'name_product_id' => 'required',
'size' => 'required',
'no' => 'required',
'address' => 'required'
]);
Order::create($createOrder);
return redirect('shops/order/{shop:id}')->with('success', 'Order is successfully!');
}
}
This is my views
#extends('layouts.main')
#section('container')
<div class="container">
<div class="row mt-5">
#foreach ($shops as $shop)
<div class="card mb-3">
<div class="row g-0">
<div class="col-md-4">
<img src="{{ asset('storage/' . $shop->image) }}" alt="{{ $shop->name_product }}" class="img-fluid rounded-start" style="max-height: 400px; overflow:hidden">
</div>
<div class="col-md-8">
<div class="card-body">
<h5 class="card-title">{{ $shop->name_product }}</h5>
<p>Jenis {{ $shop->category->name_category }}</p>
<p class="card-text fw-bold">Rp.{{ $shop->price }}</p>
</div>
</div>
</div>
</div>
#endforeach
</div>
<div class="row mt-5">
<div class="col align-self-center">
#if (session()->has('success'))
<div class="alert alert-success text-center" role="alert">
{{ session('success') }}
</div>
#endif
</div>
</div>
<form method="POST" action="/shops/order/{{ $shops }}" class="row g-2" enctype="multipart/form-data">
#csrf
<h3 class="text-center mt-2">Detail Delivery</h3>
<div class="col-md-6">
<div class="mb-3">
<select class="form-select" name="user_id" hidden>
#foreach ($users as $name)
<option value="{{ $name->id }}">{{ $name->id }}</option>
#endforeach
</select>
</div>
<div class="mb-3">
<select class="form-select" name="name_produk_id" hidden>
#foreach ($shops as $shops_id)
<option value="{{ $shops_id->id }}">{{ $shops_id->id }}</option>
#endforeach
</select>
</div>
<div class="mb-3">
<label for="address" class="form-label">Address</label>
<textarea class="form-control" #error('address') is-invalid #enderror id="address" name="address" required>
</textarea>
</div>
</div>
<div class="col-md-4">
<label for="size" class="form-label mt-3">Select size :</label>
<select class="form-select" name="size">
<option selected>S</option>
<option value="M">M</option>
<option value="L">L</option>
<option value="XL">XL</option>
</select>
<div class="mt-3">
<label for="no" class="form-label">Nomor Whatsapp</label>
<input class="form-control" #error('no') is-invalid #enderror id="no" name="no" required autofocus">
</div>
<button type="submit" class="btn btn-primary mt-5">Buy Now</button>
</div>
</form>
</div>
#endsection

how to display pdf in embed tag after click button?

I have a form with a filter and a submit button. I would like to display a pdf in an embed tag on the same page with the filter fields used when generating the pdf with Dompdf. Thanks in advance.
here is the form :
#section('content')
<!-- Your html goes here -->
<div class='panel panel-default'>
<div class='panel-heading'>Customer Statement</div>
<div class='panel-body'>
<form method='get' action="{{ route('getStatement') }}" id="statementForm">
#csrf
<div class="row">
<div class='col-sm-6 form-group'>
<div class="form-group col-6">
<label for="start_date"><strong>Start Date</strong></label>
<input type="date" required name="start_date" value="{{ date('Y-m-d') }}"
class="form-control" id="start_date">
</div>
</div>
<div class='col-sm-6 form-group'>
<div class="form-group col-6">
<label for="end_date"><strong>End Date</strong></label>
<input type="date" required name="end_date" value="{{ date('Y-m-d') }}"
class="form-control" id="end_date">
</div>
</div>
</div>
<div class='col-sm-12 form-group'>
<label> Customers :</label>
<select style="font-size: 12px; width:100%" id="customer_id" name="customer_id"
class="select2 mb-2 select2-multiple">
<option value=''> Choose </option>
#if ($customers)
#foreach ($customers as $item)
#php $selected = ''; #endphp
#if (isset($customerdirect) == $item->id)
#php $selected = 'selected'; #endphp
#endif
<option data-name="{{ $item->name }}" value='{{ $item->id }}' {{ $selected }}>
{{ $item->name }} </option>
#endforeach
#endif
</select>
</div>
</div>
<div class='panel-footer'>
<input type='submit' class='btn btn-success' value='Generate'/>
</div>
</form>
</div>
#endsection
the code in controller
public function getStatement(Request $request)
{
$pdf = PDF::loadView('customerslocations::customerstatementpdf');
return $pdf->stream();
}

Request values of contoller not getting value of select

This is a noob question, I send a post request to my controller and all it can get is the request of the input. What I want is I can also get the value of $cat array.
Here's my blade:
#if (!$categories->isEmpty())
<form action="{{route('subcategory.store')}}" method="POST">
#csrf
<div class="row">
<div class="input-group mb-3 col-md-4">
<div class="input-group-prepend">
<label class="input-group-text" for="inputGroupSelect01">Choose Category:</label>
</div>
<select class="custom-select" id="inputGroupSelect01">
#foreach ($categories as $cat)
<option value="{{$cat->id}}">{{$cat->name}}</option>
#endforeach
</select>
</div>
<input type="text" name="subcat" id="subcat" class="form-control col-md-3 ml-5">
<button type="submit" class="btn btn-success btn-lg ml-3">Save Sub Category</button>
</div>
</form>
#endif
And here's my returned value.
{"_token":"XlzwIt2jFqcybqqSjwLLJIAChG5tui7gvHzlaeAq","subcat":"xx"}
You forgot to add name="cat" in select i guess
<select class="custom-select" id="inputGroupSelect01">
simple add name="" attr
<select class="custom-select" id="inputGroupSelect01" name="cat">

Laravel - Request does not contain my inputs

I have the following form :
<div class="container text-center search-container">
<form id="search-form" action="" method="post">
<div class="nopadding col-xs-12 col-sm-2">
<select name="huge" class="form-control input-block-level selectpicker search-selector" data-style="btn-default btn-fill btn-block">
<option disabled>Search in...</option>
<option value="1" selected>foo1</option>
<option value="2">foo2</option>
<option value="3">foo3</option>
</select>
</div>
<div class="nopadding col-xs-12 col-sm-8">
<input type="text" class="form-control input-block-level search-bar" id="searchbar">
</div>
{{ csrf_field() }}
<div class="nopadding col-xs-12 col-sm-2">
<button class="btn btn-info btn-fill search-button input-block-level" type="submit">Search</button>
</div>
</form>
</div>
I use bootstrap-select for the select element.
This calls a method in my controller, however when I do a dd($request->all(), here is what I do obtain :
array:2 [▼
"huge" => "1"
"_token" => "somethingReallyLongAndBoring"
]
Basically, I am not able to retrieve my inputs. Any idea what I did wrong ?
You have to add name attribute to the input field.
<input type="text" class="form-control input-block-level search-bar" id="searchbar" name="searchbar">

Only retrieving last option in multiple select element

The form is posted and I'm retrieving the inputs with:
$inputs = Input::all();
return Response::json($inputs);
The form is like this:
<form role="form" method="POST" action="/account/enrollments/{{ $activity->id }}/update" class="form-horizontal" autocomplete="off">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="row">
<div class="col-xs-12 col-md-4">
<h4>Available Students</h4>
<select multiple class="form-control" name="available">
#foreach ($available as $student)
<option value="{{ $student->id }}">{{ $student->firstname }} {{ $student->lastname }}</option>
#endforeach
</select>
</div>
<div class="col-xs-12 col-md-4 push-top">
<button name="enrol" class="btn btn-block btn-effect-ripple btn-primary">Enrol Student(s)</button>
<button name="unenrol" class="btn btn-block btn-effect-ripple btn-warning">Remove Student(s)</button>
</div>
<div class="col-xs-12 col-md-4">
<h4>Currently Enrolled Students</h4>
<select multiple class="form-control" name="enrolled">
#foreach ($enrolled as $student)
<option value="{{ $student->id}}">{{ $student->firstname }} {{ $student->lastname }}</option>
#endforeach
</select>
</div>
</div>
</form>
But the response only shows the id of the last one selected. So, if I select three from the available select, it only returns the id of the last one, like this:
{
"_token": "KOqUu3m0uxwNxPC1BVisFT2y6P86z3uoBqZiEgTa",
"available": "5",
"enrol": ""
}
How do I retrieve all three inputs?
Here's the actual HTML from source:
<form role="form" method="POST" action="/account/enrollments/1/update" class="form-horizontal" autocomplete="off">
<input type="hidden" name="_token" value="KOqUu3m0uxwNxPC1BVisFT2y6P86z3uoBqZiEgTa">
<div class="row">
<div class="col-xs-12 col-md-4">
<h4>Available Students</h4>
<select multiple class="form-control" name="available">
<option value="2">Student 2</option>
<option value="4">Student 4</option>
<option value="5">Student 5</option>
</select>
</div>
<div class="col-xs-12 col-md-4 push-top">
<button name="enrol" class="btn btn-block btn-effect-ripple btn-primary">Enrol Student(s)</button>
<button name="unenrol" class="btn btn-block btn-effect-ripple btn-warning">Remove Student(s)</button>
</div>
<div class="col-xs-12 col-md-4">
<h4>Currently Enrolled Students</h4>
<select multiple class="form-control" name="enrolled">
<option value="3">Student 3</option>
</select>
</div>
</div>
</form>
It seems that you have to put[] in the name value:
name="available[]"
Then it returns an array.

Resources