Who can I automatically scroll to bottom of page on load in laravel - laravel-5

I want to scroll to bottom of the page on page-load automatically in laravel 5.2, i tried soo much but i couldn't figure out were i went wrong, I have attached my view code below.Can u go through it please and let me know were i went wrong. Actually i'm not good at design soo please help me on it.
my code:
#section('content')
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="col-md-3 col-sm-6 col-xs-12 profile_left">
<!-- start Support Tickets -->
<ul class="list-unstyled user_data">
<li>
<div class="panel panel-success">
<div class="panel-heading"><span class="glyphicon glyphicon-filter"></span><strong> Ticket Information</strong></div>
<div class="panel-body">
<!-- Modal -->
<table class="table table" style="color: #009933;">
#if(!empty($tickets))
<tr>
<td style="font-weight: bold; ">
<small>
{{$tickets->subject}}
</small>
</td>
</tr>
<tr>
<td style="font-weight: bold; ">
<small>
#if ($tickets->status === 'open')
<span class="label label-success">{{$tickets->status}}</span>
#elseif ($tickets->status === 'ongoing')
<span class="label label-warning">{{$tickets->status}}</span>
#elseif ($tickets->status === 'closed')
<span class="label label-default">{{$tickets->status}}</span>
#endif
</small>
</td>
</tr>
<tr>
<td style="font-weight: bold; ">
<small>
<p style="font-family: 'Times New Roman', Times, serif; ">Agent: {{\App\User::where('_id',$tickets->user_assigned)->value('username') }}</p>
</small>
</td>
</tr>
<tr>
<td style="font-weight: bold; ">
<small>
<p style="font-family: 'Times New Roman', Times, serif; ">Priority:
#if ($tickets->priority === 'Low')
<span class="label label-info">{{$tickets->priority}}</span>
#elseif ($tickets->priority === 'Medium')
<span class="label label-primary">{{$tickets->priority}}</span>
#elseif ($tickets->priority === 'High')
<span class="label label-danger">{{$tickets->priority}}</span>
#endif</p>
</small>
</td>
</tr>
<tr>
<td style="font-weight: bold; ">
<small>
<p style="font-family: 'Times New Roman', Times, serif; ">Last_Updated: {{$tickets->updated_at}}</p>
</small>
</td>
</tr>
#endif
</table>
</div>
</div>
</li>
<li>
<div class="panel panel-success">
<div class="panel-heading">
<span class="glyphicon glyphicon-dashboard"></span><strong> Support</strong>
</div>
<div class="panel-body">
<!-- Modal -->
<table class="table table-striped">
<tr>
<td><span class="glyphicon glyphicon-home"></span> My Support Tickets</td>
</tr>
<tr>
<td><span class="glyphicon glyphicon-open"></span> Submit Tickets</td>
</tr>
</table>
</div>
</div>
</li>
</ul>
<!-- end of Support Tickets -->
</div>
<div class="col-md-9 col-sm-9 col-xs-12">
<center>
<h2 style="color: #00BCD4;">My Ticket Feedback/<small>Your Comments History</small></h2>
</center>
<hr style="height:2px;border-width:0;color:gray;background-color:gray">
#if($tickets->status === 'closed')
#if(Auth::user()->_id === $tickets->user)
<div class="alert alert-warning" role="alert">
<center>
<p style="font-weight: bold; color:#FF9966; ">This Ticket is closed. You can reply to reopen this ticket.</p>
</center>
</div>
<div class="panel panel-success">
<div class="panel-heading">
<form action = "/reopentick/<?php echo $tickets->id; ?>" method = "post">
<input type = "hidden" name = "_token" value = "<?php echo csrf_token(); ?>">
<input type="hidden" name="ticket_id" value="<?php echo $tickets->id; ?>">
<input type="hidden" name="status" value="open">
<span class="glyphicon glyphicon-pencil"></span>
<input type = 'submit' value = "Reply To Reopen Ticket" class="btn btn-link btn-xs" style="font-weight: bold; color:#009933; " />
<span class="glyphicon glyphicon-plus pull-right"></span>
</form>
</div>
</div>
#endif
#endif
<table class="table table-striped">
<tr><td>
<div class="panel-group">
#if($tickets->user == Auth::user()->_id)
<div class="panel panel-info">
#else
<div class="panel panel-success">
#endif
<div class="panel-heading">
<span class="glyphicon glyphicon-user">
<strong>
{{ \App\User::where('_id',$tickets->user)->value('username') }}
</strong>
</span>
<span class="glyphicon glyphicon-time pull-right">
{{ $tickets->created_at }}</br>
</span>
</div>
<div class="panel-body">
<p> Hello,</br>
{!! $tickets->message !!}</br>
<b>...</b></br>
Thank you,</br>
{{ \App\User::where('_id',$tickets->user)->value('username') }}
</p>
</div>
</div>
</div>
</td></tr>
<tr>
#foreach($anstickets as $t)
<td class="answer_block">
<div class="panel-group">
#if($t->user_id == Auth::user()->_id)
<div class="panel panel-info">
#else
<div class="panel panel-success">
#endif
<div class="panel-heading">
<span class="glyphicon glyphicon-user ">
<strong>
{{ \App\User::where('_id',$t->user_id)->value('username') }}
</strong>
</span>
<span class="glyphicon glyphicon-time pull-right">
{{ $t->created_at }}</br>
</span>
</div>
<div class="panel-body">
<p>Hi,</p>
{!!$t->comments!!}</br>
</div>
</div>
</div>
</td>
</tr>
#endforeach
</table>
#if(($tickets->status === 'ongoing')||($tickets->status === 'open'))
#if(Auth::user()->_id === $tickets->user)
<div class="panel panel-danger">
<div class="panel-heading">
<form action = "/closetick/<?php echo $tickets->id; ?>" method = "post" >
<input type = "hidden" name = "_token" value = "<?php echo csrf_token(); ?>">
<input type="hidden" name="ticket_id" value="<?php echo $tickets->id; ?>">
<input type="hidden" name="status" value="closed">
<input type = 'submit' value = "Close Ticket" class="btn btn-link btn-xs" style="font-weight: bold; color:#CC0000; "/>
<span class="glyphicon glyphicon-remove-sign pull-right"></span>
</form>
</div>
</div>
#endif
<br>
#if(Auth::user()->_id === $tickets->user)
<b><h1> Response</h1></b>
#else
<b><h1> Solution</h1></b>
#endif
<form action = "/tickanswert/<?php echo $tickets->id; ?>" method = "post" onsubmit="return form_submit()">
<input type = "hidden" name = "_token" value = "<?php echo csrf_token(); ?>">
<input type="hidden" name="user_id" value="<?php echo Auth::user()->id; ?>">
<input type="hidden" name="ticket_id" value="<?php echo $tickets->id; ?>">
<div class="form-group">
<textarea class="form-control" name="comments" rows="14" required></textarea>
</div>
<br>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" name="submit" class="btn btn-primary btn-lg">
<i class="fa fa-btn fa-ticket"></i> SUBMIT
</button>
</div>
</div>
</form>
#endif
</div>
</div>
#endsection
#section('additional-scripts')
<script>
$( document ).ready(function() {
$('html,body').animate({
scrollTop: $('.answer_block').children('.panel-group').last().offset().top},
'slow');
alert("Hello! I am an alert box!!");
});
</script>
#endsection

Laravel cannot scroll to bottom of page. But Javascript can:
<script>
$(document).ready(function() {
$('html,body').animate({scrollTop: document.body.scrollHeight},"slow");
})
</script>

Related

Submitted form detected an empty object Request in laravel

When creating an order I need to redirect to a new page to enter the information of ordered materials and store the pivot(order, material), but when I submitted the form on the second page the request element detected empty and I can't recovery my inputs values to store it, I don't understand why it doesn't work
the form code :
<form class="form-material" action="{{ route('commandeMateriaus.store') }}" method="POST">
#csrf
<div style="margin-bottom: 20px; color:black;">
<div style="padding-right: 50px;">
<div >
<span style="margin-right: 50px;"> <span style="font-weight: bold;"> Code de la commande : </span><input type="text" name="code_commande" value="{{ $commande->code_commande }}" style="border:none;" readonly> </span>
</div>
<span style="margin-right: 50px;"> <span style="font-weight: bold;"> Date de la commande : </span> {{ $commande->date_commande }} </span>
<span style="margin-right: 50px;"> <span style="font-weight: bold;"> Fournisseur : </span> {{ $fournisseur->intitule_fournisseur }}</span>
</div>
</div>
<div style="margin-bottom: 20px;">
<div class="row">
<div class="col-6">
<div class="form-group form-primary form-static-label">
<label class="form-label " style="top: -14px; color: black;">Matériaux <span class="text-danger">*</span> </label>
<div class="select">
<select id="mySelect" class="materiaux form-control" name="materiaus[]" multiple size="5">
#foreach($materiaus as $materiau)
<option value="{{ $materiau->id }}"> {{ $materiau->intitule_materiau }} </option>
#endforeach
</select>
</div>
<span class="form-bar"></span>
</div>
</div>
</div>
</div>
<div>
<h5>Liste des matériaux commandés :</h5>
<table class="table m-b-0 text-center">
<thead>
<td>Matériau</td>
<td>Prix Unitaire</td>
<td>Quantité</td>
<td>Montant</td>
</thead>
<tbody >
#foreach($materiaus as $materiau)
<tr style="display:none;" id="{{ $materiau->id }}" class="data">
<td > {{ $materiau->intitule_materiau }} </td>
<td> <input type="text" id="prix{{ $materiau->id }}" name="prix_unit_materiau" value="{{ $materiau->prix_unit_materiau }}" style="border:none;" readonly> </td>
<td > <input type="number" class="quantite" id="q{{ $materiau->id }}" name="quantite_materiau" style="border:none;" placeholder="Entrer la quantité" onchange="recupValeur(this.value, this.id);"> </td>
<td ><input type="decimal" class="montant" id="montant{{ $materiau->id }}" name="montant_materiau" value="0" style="border:none;" readonly></td>
</tr>
#endforeach
<tr>
<td colspan="4" style="text-align:right;" >Total</td>
<td ><input type="decimal" name="total_commande" value="0" style="border:none;" id="total" readonly></td>
</tr>
</tbody>
</table>
</div>
<div class=" text-right" style="margin-top: 10px;">
<button type="submit" class="btn btn-primary"> <i class="fa fa-fw fa-plus-circle" > </i> Ajouter</button>
<button type="reset" class="btn btn-info" style="margin-left: 10px;"><i class="fa fa-fw fa-sync" ></i> Réinitialiser</button>
</div>
</form>
the store method
public function store(Request $request)
{
$request->validate([
'code_commande' => 'required',
'materiaus' => 'required',
'quantite_materiau' => 'required',
'montant_materiau' => 'required',
'total_commande' => 'required'
]);
$cm = new CommandeMateriau();
$commande = Commande::where('code_commande', '=', $request->code_commande)->first();
$commande_id = $commande->id;
$commande->total_commande = $request->total_commande;
$commande->save();
$cm->commande_id = $commande_id;
$cm->quantite_materiau = $request->quantite_materiau;
$cm->montant_materiau = $request->montant_materiau;
foreach ($request->materiaus as $materiau){
$cm->materiau_id = $materiau->id;
$cm->save();
}
return redirect()->back()
->with('success','Enregistrement ajouté avec succes.');
}
Can someone help me, please
Because you have an input type of array, try to add this enctype="multipart/form-data" inside your form tag.
<form class="form-material" action="{{ route('commandeMateriaus.store') }}" method="POST" enctype="multipart/form-data" >

Failed to load excel\laravel-excel

I want to export only filtered data in view blade. I am using Laravel 7 and maatwebsite/excel 3.1 and PHP 7.4.2.
I went through the documentation and applied this:
View
<a href="{!! route('users.export-filter') !!}" class="btn btn-success">
<i class="la la-download"></i>
Export Filter
</a>
web.php
Route::get('/users/export-filter', 'Admin\UserController#filter')->name('users.export-filter');
UserController.php
public function filter()
{
return Excel::download(new FilterUserExport, 'filter.xlsx');
}
FilterUserExport.php
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\AfterSheet;
use Modules\User\Entities\User;
use Illuminate\Contracts\View\View;
class FilterUserExport implements FromView, ShouldAutoSize, WithEvents
{
/**
* #return View
*/
public function view(): View
{
$users = app(User::class)->newQuery();
if ( request()->has('search') && !empty(request()->get('search')) ) {
$search = request()->query('search');
$users->where(function ($query) use($search) {
$query->where('first_name', 'LIKE', "%{$search}%")
->orWhere('last_name', 'LIKE', "%{$search}%")
->orWhere('email', 'LIKE', "%{$search}%")
->orWhere('mobile', 'LIKE', "%{$search}%");
});
}
return view('users.index', compact('users'));
}
/**
* #return array
*/
public function registerEvents(): array
{
return [
AfterSheet::class => function(AfterSheet $event) {
$event->sheet->getDelegate()->setRightToLeft(true);
},
];
}
}
index.blade.php
#extends("admin-panel.layouts.master")
#section("content")
<div class="content-body">
<section class="grid-with-inline-row-label" id="grid-with-inline-row-label">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h4 class="card-title">
<a data-action="collapse">
<i class="ft-plus mr-1"></i>
ثبت فیلتر
</a>
</h4>
<a class="heading-elements-toggle"><i class="ft-align-justify font-medium-3"></i></a>
<div class="heading-elements">
<ul class="list-inline mb-0">
<li><a data-action="collapse"><i class="ft-plus"></i></a></li>
<li><a data-action="reload"><i class="ft-rotate-cw"></i></a></li>
<li><a data-action="expand"><i class="ft-maximize"></i></a></li>
<li><a data-action="close"><i class="ft-x"></i></a></li>
</ul>
</div>
</div>
<div class="card-content collapse #if( $errors->any() ) show #endif">
<div class="card-body">
<form action="{!! route('admin::users.index') !!}" method="get">
<div class="form-body">
<div class="row">
<div class="col-6 form-group">
<label for="search">جستجو</label>
<input type="text" name="search" id="search" class="form-control"
placeholder="جستجو..."
aria-label="جستجو" value="{{ request()->query('search') }}">
</div>
<div class="col-6 form-group">
<label for="user_type">گروه کاربری</label>
<select id="user_type" name="user_type" class="form-control">
<option value="" {{ (request()->query('user_type') == '')? "selected" : "" }}>-</option>
<option value="is_special" {{ (request()->query('user_type') == 'is_special')? "selected" : "" }}>کاربر ویژه</option>
<option value="is_user" {{ (request()->query('user_type') == 'is_user')? "selected" : "" }}>کاربر عادی</option>
<option value="is_admin" {{ (request()->query('user_type') == 'is_admin')? "selected" : "" }}>مدیریت سیستم</option>
</select>
</div>
<div class="col-6 form-group">
<label for="target">فیلتر کاربران</label>
<select id="target" name="target" class="form-control">
<option value="" {{ (request()->query('target') == '')? "selected" : "" }}>-</option>
<option value="active" {{ (request()->query('target') == 'active')? "selected" : "" }}>کاربر ویژه</option>
<option value="orderedAtLeastOnce" {{ (request()->query('target') == 'orderedAtLeastOnce')? "selected" : "" }}>کاربر عادی</option>
<option value="orderedInLastMonth" {{ (request()->query('target') == 'orderedInLastMonth')? "selected" : "" }}>مدیریت سیستم</option>
<option value="neverOrdered" {{ (request()->query('target') == 'neverOrdered')? "selected" : "" }}>مدیریت سیستم</option>
</select>
</div>
<div class="col-md-6 form-group">
<label for="categoryId">دسته بندی</label>
{!! Form::select('categoryId', \Modules\Category\Entities\Category::whereNull('parentId')->get()->pluck('title', 'id')->toArray(), null, [
'class' => 'form-control',
'id' => 'categoryId',
'placeholder' => 'انتخاب دسته بندی',
]) !!}
</div>
</div>
<div class="d-flex justify-content-between form-actions pb-0">
<div>
<button type="submit" class="btn btn-primary">ارسال <i class="ft-send position-right"></i>
</button>
<button type="reset" class="btn btn-warning">ریست <i class="ft-refresh-cw position-right"></i>
</button>
</div>
<div>
<a href="{!! route('admin::users.export-excel') !!}" class="btn btn-success">
<i class="la la-download"></i>
صادر
</a>
<a href="{!! route('admin::users.export-filter') !!}" class="btn btn-success">
<i class="la la-download"></i>
Export Filter
</a>
<a href="{!! route('admin::users.export-special-excel') !!}" class="btn btn-success">
<i class="la la-download"></i>
صدور کاربران ویژه
</a>
<a href="{!! route('admin::users.import-excel') !!}" class="btn btn-primary">
<i class="la la-cloud-download"></i>
آپلود
</a>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div id="recent-transactions" class="col-xl-12 col-12">
<div class="card">
<div class="card-header">
<div class="row">
<div class="col-md">
<div class="row justify-content-between align-items-center mr-md-1 mb-1">
<div class="col-sm">
<h4 class="card-title mb-2 mb-sm-0">فهرست کاربران</h4>
</div>
</div>
</div>
<div class="col-auto">
<a href="{!! route('admin::users.create') !!}" class="btn btn-info">
<i class="la la-plus"></i>
ایجاد کاربر جدید
</a>
</div>
</div>
</div>
<div class="card-content">
#if( $users->count() > 0 )
#includeWhen( Module::find('notification') && request()->has('search'), 'user::admin.users._notification' )
<div class="table-responsive">
<table id="recent-orders" class="table table-hover table-xl mb-0">
<thead>
<tr>
<th class="border-top-0"># شناسه</th>
<th class="border-top-0">نام و نام خانوادگی</th>
<th class="border-top-0">موبایل</th>
{{-- <th class="border-top-0">ایمیل</th>--}}
<th class="border-top-0">کد ملی</th>
<th class="border-top-0">مدیر</th>
<th class="border-top-0">وضعیت</th>
<th class="border-top-0">ویژه</th>
<th class="border-top-0">آخرین ورود</th>
<th class="border-top-0">عملیات</th>
</tr>
</thead>
<tbody>
#foreach($users as $user)
<tr>
<td class="text-truncate">
<i class="la la-dot-circle-o success font-medium-1 mr-1"></i>
{{ $user->id }}
</td>
<td class="text-wrap">
{{ $user->first_name.' '.$user->last_name }}
</td>
<td class="text-wrap">
{{ $user->mobile }}
</td>
{{--<td class="text-wrap">
{{ $user->email }}
</td>--}}
<td class="text-wrap">
{{ $user->national_id }}
</td>
<td class="text-wrap">
#if( $user->is_admin )
<i class="ft-check-circle text-success"></i>
#else
<i class="ft-x-circle text-danger"></i>
#endif
</td>
<td class="text-wrap">
#if( !$user->disabled_at )
<i class="ft-check-circle text-success"></i>
#else
<i class="ft-x-circle text-danger"></i>
#endif
</td>
<td class="text-wrap">
#if( $user->is_special_user == 1 )
<i class="ft-check-circle text-success"></i>
#else
<i class="ft-x-circle text-danger"></i>
#endif
</td>
<td class="text-wrap">
#if( $user->last_login_at )
{{ getShamsiDate($user->last_login_at) }}
#else
—
#endif
</td>
<td>
<div class="row flex-nowrap">
<a href="{{ route('admin::users.show', $user) }}" class="mr-1">
<i class="ft-eye text-grey text-shadow-custom font-medium-5 font-weight-normal"></i>
</a>
<a href="{{ route('admin::users.edit', $user) }}" class="mr-1">
<i class="ft-edit text-grey text-shadow-custom font-medium-4 font-weight-normal"></i>
</a>
<form action="{{ route('admin::users.destroy', $user) }}"
method="post"
#submit.prevent="confirmDelete">
#method('delete')
#csrf
<button type="submit" class="btn btn-default p-0">
<i class="ft-trash-2 text-grey font-medium-5 font-weight-normal"></i>
</button>
</form>
</div>
</td>
</tr>
#endforeach
</tbody>
</table>
<div class="pagination-flat">
{{ $users->links() }}
</div>
</div>
#else
<div class="text-center my-2">
<p>نتیجه‌ای برای نمایش وجود ندارد.</p>
</div>
#endif
</div>
</div>
</div>
</div>
</section>
</div>
#endsection
I get this error
The export submit button is sending everything to Excel. How do I make it to send only the filtered data. Thanks
You need to get rid of the other HTML in your view such as forms, inputs, and buttons. Keep the view only to a minimum of the table that needed for your Excel.

Getting validation to work for address in laravel

I'm making a page that before the user submits they need to add their address.
For example: The user goes to the order confirmation and they forget to add their address and they fill in the rest of the page (the page has delivery/collection radio buttons and payment option radio buttons) when the user clicks on the confirm button the page needs to go back and give an error that the address wasn't entered.
The address portion of the page only has a "Add Address" button that takes the user to a form to enter their address.
Is there a way to do this. I thought maybe validation would work but I don't think I'm doing it correctly in this instance.
I have a hidden form that grabs some info and it has an address field in it so that it gets passed into the controller so that I can save it, but it's like it doesn't pick it up
My order-confirmation.blade.php
#extends('layouts.public')
#section('content')
<div class="content_wrapper">
<h1>Order Confirmation</h1>
<?php
$delivery = getDeliveryFee();
?>
{{ $invoice_number }}
<div class="row">
<div class="col-lg-12">
<div class="row">
<div class="col-lg-12 mt-15">
#if($message = Session::get('success'))
<div class="alert alert-success" role="alert">
{{ $message }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
#endif
#if($message = Session::get('error'))
<div class="alert alert-danger" role="alert">
{{ $message }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
#endif
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="accordion" id="accordionExample">
<div class="card">
<div class="card-header" id="headingOne">
<h2 class="mb-0">
<button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Billing Information
</button>
</h2>
</div>
<div id="collapseOne" class="collapse {{ !$errors->any() ? 'show' : '' }}" aria-labelledby="headingOne" data-parent="#accordionExample">
<div class="card-body">
<div class="row">
<div class="col-lg-6">
<div class="address">
#if ($errors->confirmation_errors->has('delivery_address'))
<div class="help-block text-danger">
<strong>Please add an address NOW</strong>
</div>
#endif
#foreach($addresses as $address)
#if(!empty($address->complex))
{{ $address->complex }},
#endif
<div>{{ $address->address }},</div>
<div>{{ $address->suburb }},</div>
<div>{{ $address->city }},</div>
<div>{{ $address->province }},</div>
<div>{{ $address->postal_code }}</div>
<div class="row edit-delete">
<div class="col-lg-2">
<a class="btn btn-primary edit-button" href="{{ route('account.edit.delivery.address', [$address->id]) }}">Edit</a>
<span>/</span>
</div>
<div class="col-lg-2">
<form action="{{ route('account.delete.delivery.address', [$address->id]) }}" method="post">
#csrf
{{ method_field('DELETE') }}
<button class="btn btn-danger delete-button"><i class="fa fa-pencil"></i> Delete</button>
</form>
</div>
</div>
#endforeach
</div>
</div>
<div class="col-lg-6">
Add Address
</div>
</div>
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingTwo">
<h2 class="mb-0">
<button class="btn btn-link collapsed" id="delivery-collection" type="button" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Delivery/Collection
</button>
</h2>
</div>
<div id="collapseTwo" class="collapse {{ $errors->confirmation_errors->any() ? 'show' : '' }}" aria-labelledby="headingTwo" data-parent="#accordionExample">
<div class="card-body">
<p>
Please select your delivery option
</p>
#if ($errors->confirmation_errors->has('delivery_collection'))
<div class="help-block text-danger">
<strong>Please select your delivery option</strong>
</div>
#endif
<div class="delivery-option">
<input type="radio" class="form-check-input {{ $errors->confirmation_errors->has('delivery_collection') ? 'is-invalid' : '' }}" name="delivery-option" id="delivery" value="delivery">
<label for="delivery" class="form-check-label">
Delivery
</label>
<input type="radio" class="form-check-input {{ $errors->confirmation_errors->has('delivery_collection') ? 'is-invalid' : '' }}" name="delivery-option" id="collection" value="collection">
<label for="collection" class="form-check-label">
Collection
</label>
</div>
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingThree">
<h2 class="mb-0">
<button class="btn btn-link collapsed" type="button" data-toggle="collapse" data-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
Payment Options
</button>
</h2>
</div>
<div id="collapseThree" class="collapse {{ $errors->any() ? 'show' : '' }}" aria-labelledby="headingThree" data-parent="#accordionExample">
<div class="card-body">
#if ($errors->has('payment_option'))
<div class="help-block text-danger">
<strong>Please select a payment option</strong>
</div>
#endif
<div class="row">
<div class="col-lg-12">
<div class="payment-option">
<input type="radio" class="form-check-input {{ $errors->has('payment_method') ? 'is-invalid' : '' }}" name="payment_method" id="payfast-eft" value="payfast-eft">
<label for="payfast-eft" class="form-check-label">
EFT with PayFast
</label>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingThree">
<h2 class="mb-0">
<button class="btn btn-link collapsed" type="button" data-toggle="collapse" data-target="#collapseFour" aria-expanded="false" aria-controls="collapseThree">
Review Your Order
</button>
</h2>
</div>
<div id="collapseFour" class="collapse" aria-labelledby="collapseFour" data-parent="#accordionExample">
<div class="card-body">
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">Product</th>
<th scope="col">Code</th>
<th scope="col">Quantity</th>
<th scope="col">Unit Price</th>
<th scope="col">Total</th>
</tr>
</thead>
<tbody>
#foreach($products as $product)
<?php
$image = getImagesArray($product['item']['image']);
?>
<tr>
<th>
#if(!empty($image))
<img src={!! asset("product_images/thumbs/$image[0]") !!}>
#endif
{{ $product['item']['title'] }}
</th>
<td>{{ $product['item']['supplier_code'] }}</td>
<td>{{ $product['qty'] }}</td>
<td>R {{ $product['item']['price'] }}</td>
<td>R {{ $product['price'] }}</td>
</tr>
#endforeach
<tr>
<th colspan="4">
<div class="float-right">
Sub Total
</div>
</th>
<td id="totalPrice" data-price="{{ $totalPrice }}">
R {{ $totalPrice }}
</td>
</tr>
<tr class="delivery-fees">
<th colspan="4">
<div class="float-right">
Delivery Fee
</div>
</th>
<td id="delivery-price" data-price="{{ $delivery }}">
R {{ $delivery }}
</td>
</tr>
<?php
$total = $totalPrice + $delivery;
?>
<tr class="total-price">
<th colspan="4">
<div class="float-right">
Total:
</div>
</th>
<td>
R <span id="completePrice"></span>
</td>
</tr>
</tbody>
</table>
<div class="confirm-order-btn pb-15">
#foreach($products as $product)
<!-- BEGIN PAYFAST EFT -->
<div class="payfast-eft" style="display: none">
<form action="{{ route('payment.gateway') }}" method="POST">
#csrf
<input type="hidden" name="merchant_id" value="merchant_id">
<input type="hidden" name="merchant_key" value="merchant_key">
<input type="hidden" name="return_url" value="{{ route('payfast.success') }}">
<input type="hidden" name="cancel_url" value="{{ route('payfast.cancel') }}">
<input type="hidden" name="m_payment_id" value="{{ $invoice_number }}">
<input type="hidden" name="amount" class="completePrice" value="">
<input type="hidden" name="item_name" value="{{ $product['item']['title'] }}">
<input type="hidden" name="item_description" value="{{ $product['item']['description'] }}">
<input type="hidden" name="email_confirmation" value="1">
<input type="hidden" name="confirmation_address" value="">
<input type="hidden" name="payment_method" value="payfast_eft">
<input type="hidden" name="delivery_collection" class="delivery_collection" value="">
<input type="hidden" name="delivery_fee" class="delivery_fee" value="{{ $delivery }}">
<!-- THIS IS WHERE THE ADDRESS IS ADDED TO THE HIDDEN FORM -->
<input type="hidden" name="delivery_address" class="delivery_address" value="{{ $address }}">
<?php
$success = url('payfast-success');
$cancel = url('payfast-cancel');
$notify = url('payfast-notify');
$original_str = getAscii('merchant_id=merchant_id&merchant_key=merchant_key&return_url='.$success.'&cancel_url='.$cancel.'&notify_url='.$notify.'&m_payment_id=01AB&amount='.$totalPrice.'&item_name=Test Item&item_description=A test product&email_confirmation=1&confirmation_address=email#domain.com&payment_method=eft');
$hash_str = hash('MD5', $original_str);
$hash = strtolower($hash_str);
?>
<input type="hidden" name="signature" value="{{ $hash }}">
<button type="submit" class="btn btn-success float-right confirm-payfast-order">
Confirm Order
</button>
</form>
</div>
<!-- END PAYFAST EFT -->
#endforeach
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
var price = $("#totalPrice").data('price'); //get data-price by this syntax
$('#completePrice').html(price);
$('.completePrice').val(price);
$('input[type="radio"]').click(function(){
if($(this).attr("value")=="collection"){
$(".delivery-fees").hide('slow');
var price = $("#totalPrice").data('price'); //get data-price by this syntax
var deliveryprice = 0; //get data-price by this syntax
var totalPrice = parseFloat(price) + parseFloat(deliveryprice);
$('#completePrice').html(totalPrice);
$('.completePrice').val(totalPrice);
$('.delivery_collection').val('collection');
$('.confirm-order').removeAttr('disabled');
$('.confirm-payfast-order').removeAttr('disabled');
}
if($(this).attr("value")=="delivery"){
$(".delivery-fees").show('slow');
var price = $("#totalPrice").data('price'); //get data-price by this syntax
var deliveryprice = $("#delivery-price").data('price'); //get data-price by this syntax
var totalPrice = parseFloat(price) + parseFloat(deliveryprice);
$('#completePrice').html(totalPrice);
$('.completePrice').val(totalPrice);
$('.delivery_collection').val('delivery');
}
});
/* BEGIN EFT PAYFAST */
$('input[type="radio"]').click(function(){
if($(this).attr("value")=="payfast-eft"){
$(".payfast-eft").show('slow');
$(".payfast-card").hide();
$(".i-pay").hide();
$(".confirm-order").hide();
$(".payfast-debit-card").hide();
}
});
/* END EFT PAYFAST */
});
</script>
#stop
my controller function
public function paymentGateway(Request $request)
{
if($request->payment_method == 'payfast_eft')
{
$process = 'Order Paid';
$paid = '1';
}
if($request->delivery_collection == 'collection')
{
$delivery_fee = null;
}else{
$delivery_fee = $request->delivery_fee;
}
$orders = Order::all();
$oldCart = Session::get('cart');
$cart = new Cart($oldCart);
$validation = Validator::make($request->all(), $this->getRules());
if($validation->fails())
{
return redirect()->route('cart.deliveryConfirmation')
->withErrors($validation, 'confirmation_errors')
->with('error', 'There were validation errors');
}
foreach($orders as $order)
{
$order = Order::find($order->id)->where('invoice_number', $request->m_payment_id)->first();
$order->cart = serialize($cart);
$order->address = $request->delivery_address;
$order->delivered_date = null;
$order->delivery_fee = $delivery_fee;
$order->delivery_option = $request->delivery_collection;
$order->process = $process;
$order->order_date = Carbon::now('+2:00');
$order->payment_method = $request->payment_method;
$order->paid = $paid;
$order->order_price = $request->amount;
$order->save();
}
$merchant_id = $request->merchant_id;
$merchant_key = $request->merchant_key;
$return_url = $request->return_url;
$cancel_url = $request->cancel_url;
$m_payment_id = $request->m_payment_id;
$amount = $request->amount;
$item_name = $request->item_name;
$item_description = $request->item_description;
$email_confirmation = '1';
$confirmation_address = 'email#domain.com';
$payment_method = $request->payment_method;
$signature = $request->signature;
if($request->payment_method == 'payfast_eft')
{
$url = 'https://sandbox.payfast.co.za/eng/process?merchant_id='.$merchant_id.'&merchant_key='.$merchant_key.'&return_url='.$return_url.'&cancel_url='.$cancel_url.'&m_payment_id='.$m_payment_id.'&amount='.$amount.'&item_name='.$item_name.'&item_description='.$item_description.'&email_confirmation='.$email_confirmation.'&confirmation_address='.$confirmation_address.'&payment_method='.$payment_method;
}
return redirect()->to($url);
}
protected function getRules()
{
return [
'delivery_collection' => 'required',
'payment_method' => 'required',
'delivery_address' => 'required'
];
}
basically on the paymentGateway controller you need to check whether the address is provided if not redirect to the previous page where address is selected and saved in db

DataTables Custom Search in Laravel

I'm using laravel to create a contact page, and this is my view code:
<table id="example">
<thead>
<tr>
<th class="no-sort"></th>
</tr>
</thead>
<tbody>
<?php $idx = 1; ?>
#foreach($users as $result)
#if($idx == 1) <tr> #endif
<td class="col-md-4 col-sm-4 col-xs-12 animated fadeInDown">
<div class="well profile_view">
<div class="col-sm-12">
<h4 class="brief"><i>Digital Strategist</i></h4>
<div class="left col-xs-7">
<h2>{!! $result->first_name !!}</h2>
<p><strong>Username: </strong> {!! $idx !!} </p>
<ul class="list-unstyled">
<li>{!! $result->email !!}</li>
</ul>
</div>
<div class="right col-xs-5 text-center">
#if($result->image)
{!! Html::image('packages/calibre/images/profile/'.$result->image, '', array("class"=>"img-circle img-responsive")) !!}
#else
{!! Html::image('packages/calibre/images/profile/none.png', '', array("class"=>"img-circle img-responsive")) !!}
#endif
</div>
</div>
<div class="col-xs-12 bottom text-center">
<div class="col-xs-12 col-sm-12 emphasis">
<button type="button" class="btn btn-success btn-xs pull-left"><i class="fa fa-check"></i> Active</button>
<button type="button" class="btn btn-primary btn-xs pull-right"><i class="fa fa-search"></i> View Profile </button>
</div>
</div>
</div>
</td>
#if($idx == 3) </tr> #endif
<?php if($idx == 3) $idx = 1; else $idx++; ?>
#endforeach
</tbody>
</table>
the layout is not like common tables, it's using tag from it's template.
How to enable it using DataTables to search and paging? anyone could help me?

loading popup jsp page on view jsp without page refresh using jQuery-ajax

I've two jsp pages 1.view.jsp,2.popup.jsp (it is a popup page).the popup.jsp will be loaded when I click the 'add icon' on my view.jsp. Just I want to know how to load values on my 'view.jsp' (without refreshing the page) when 'submit' button is clicked on my 'popup.jsp' using Ajax.
view.jsp
<body>
<div class="st-content">
<jsp:include page="/WEB-INF/jsp/settings/adminmenu.jsp" />
<div class="width1">
<div class="mgmt-menu-bar font-new">
<div class="margin-left10 margin-top line-height1 ">
<a href="executeIndustry">
<div class="menunew cursor red">
<i class="icon-list icon-grey1"></i> Industry</div>
</a>
<a href="viewDepartment">
<div class="menunew cursor" ><i class="icon-list icon-grey1"></i> Department</div>
</a>
<a href="addViewDesignation">
<div class="menunew cursor" ><i class="icon-list icon-grey1"></i> Designation</div>
</a>
</div>
</div>
<div class="mgmt-content-right">
<div class="width2 margin-left10">
<div class="content-table-full">
<div class="content-h bold margin-left margin-top">Industry
<div class="top-right-icon2 cursor" data-toggle="tooltip" title="Add Industry" onclick="TINY.box.show({iframe:'addPageIndustry.action',boxid:'frameless',width:456,height:200, fixed:false,maskid:'bluemask',maskopacity:40})" >
<i class="icon-plus icon-grey1"></i>
</div>
</div>
<s:form action="executeIndustry" name="paginationForm" id="paginationForm">
<s:hidden name="industryId" id="industryId"/>
<s:if test="%{success!=null}" >
<div id="error" style="color:#048350;margin-top: 10px" >
<s:property value="success"/>
<br/>
</div>
</s:if>
<s:if test="%{error!=null}" >
<div id="error" style="color: #FF0000;margin-top: 10px">
<s:property value="error"/>
<br/>
</div>
</s:if>
<table width="100%" cellpadding="0" cellspacing="0" class="margin-bottom margin-top table-display">
<tr class="row-header">
<td >
Industry </td>
<td width="450">Created Date</td>
<td width="200">Action</td>
</tr>
<s:if test="%{industrylist!= null && industrylist.size > 0}">
<s:iterator value="industrylist">
<tr class="row1">
<td > <s:property value="industryName"/></td>
<td> <s:date name="createdDate" format="dd/MM/yyyy hh:mm:ss a"/></td>
<td>
<i class="icon-edit icon-grey1 cursor" title="Edit" data-toggle="tooltip" onclick="TINY.box.show({iframe:'editIndustry.action?editid=<s:property value="industryId"/>',boxid:'frameless',width:456,height:200, fixed:false,maskid:'bluemask',maskopacity:40})"></i>
<i title="Delete" data-toggle="tooltip" onclick="deletethis('<s:property value="industryId"/>')" class="icon-minus-sign icon-grey1 cursor"></i>
</td>
</tr>
</s:iterator>
</s:if>
<s:else>
<tr class="row1">
<td colspan="4" align="center">No industries were found</td>
</tr>
</s:else>
<s:hidden name="deleteid" id="deleteid"></s:hidden>
</table>
<div class="width2">
<s:if test="%{industrylist.size()>0}">
<%# include file="/WEB-INF/jsp/pagenation/pagination.jsp" %>
</s:if>
</div>
</s:form>
</div>
</div>
</div>
</div>
</div>
<jsp:include page="/common/commonfooter.jsp" />
<script type="text/javascript" src="shared/scripts/js/pagination.js"></script>
</div>
popup.jsp
<body>
<div class="pop-box">
<s:if test="%{edit!=1}" >
<s:form action="addIndustry" method="post" id="FormOne" name="FormOne" target="_top" cssClass="validate">
<span style="margin-left:10px;" class="heading-st2">Add Industry</span>
<div class="popup-style">
<div class="row-form">
<span class="red">*</span>Industry
</div>
<div class="row-form ">
<s:textfield name="industryName" id="industryName" cssClass="input-xlarge required-field" oncopy="return false" onpaste="return false" oncut="return false" onkeypress="return isNumberKey(event)" maxlength="60" />
</div>
<div class="row-form">
<button type="submit" class="btn btn-success ">Submit <i class="icon-ok icon-white"></i></button>
<span class="help-inline"></span>
</div>
</div>
</s:form>
</s:if>
<s:else>
<s:form action="updateIndustry" method="post" id="FormOne" name="FormOne" target="_top" cssClass="validate">
<s:hidden name="industryId"/>
<span style="margin-left:10px;" class="heading-st2">Edit Industry</span>
<div class="popup-style">
<div class="row-form">
<span class="red">*</span>Industry
</div>
<div class="row-form ">
<s:textfield name="industryName" id="industryName" cssClass="input-xlarge required-field" oncopy="return false" onpaste="return false" oncut="return false" onkeypress="return isNumberKey(event)" maxlength="60" />
</div>
<div class="row-form">
<button type="submit" class="btn btn-success ">Submit <i class="icon-ok icon-white"></i></button>
<span class="help-inline">
</span>
</div>
</div>
</s:form>
</s:else>
</div>
$(document).ready(function(){
var frm = $('#myform');
frm.submit(function (ev) {
$.ajax({
type: frm.attr('method'),
url: frm.attr('action'),
data: frm.serialize(),
success: function (data) {
alert("submitted");
},
error:function(data){
alert("error");
}
});
window.scrollTo(0,0);
ev.preventDefault();
});
The above jquery ajax helps you to accompany your action submittion without refreshing...

Resources