Displaying photo after uploaded Using Ajax - Laravel - ajax

I need a help please
My question is : How can I display image after uploaded it in the same Page
I'm trying a lot of code , but nothing is worked for me
Here is blade code
<form action="{{ route('admin.user.store') }}" method="post" class="form-horizontal"
enctype="multipart/form-data" id ="upload_form">
#csrf
<div class="row justify-content-center">
<div class="col-xl-9">
<!--begin::Wizard Step 1-->
<div class="my-5 step" data-wizard-type="step-content" data-wizard-state="current">
<h5 class="text-dark font-weight-bold mb-10">User's Profile Details:</h5>
<!--begin::Group-->
<div class="form-group row">
<label class="col-xl-3 col-lg-3 col-form-label text-left">Avatar</label>
<div class="col-lg-9 col-xl-9">
<div class="image-input image-input-outline" id="kt_user_add_avatar">
<div class="image-input-wrapper" >
<img src="{{asset('assets/media/users/100_6.jpg')}}" width="120" height="120">
</div>
<label class="btn btn-xs btn-icon btn-circle btn-white btn-hover-text-primary btn-shadow" data-action="change" data-toggle="tooltip" title="" data-original-title="Change avatar">
<i class="fa fa-pen icon-sm text-muted"></i>
<input id="avatar" type="file" name="avatar" accept=".png, .jpg, .jpeg" />
</label>
<span class="btn btn-xs btn-icon btn-circle btn-white btn-hover-text-primary btn-shadow" data-action="cancel" data-toggle="tooltip" title="Cancel avatar">
<i class="ki ki-bold-close icon-xs text-muted"></i>
</span>
</div>
</div>
</div>
<!--end::Group-->
<div class="form-actions">
<div class="row">
<div class="col-md-offset-3 col-md-9">
<button type="submit" class="btn" style="background-color:#3699FF">Submit</button>
Cancel
</div>
</div>
</div>
</div>
</div>
</form>

Try this: (For Preview)
<script type="text/javascript">
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
</script>
<input id="avatar" type="file" name="avatar" accept=".png, .jpg, .jpeg" onchange="readURL(this);" />
<img id="blah" src="#" alt="your image" />

Related

Ckeditor 5 classic in textarea in Laravel Liveware, the form will not be submitted

I use Ckeditor 5 classic in textarea in Laravel Liveware, the form will not be submitted.
How can I solve this problem?
This form is bootstrap modal form. when i use ckeditor code in app.blade.php then the form are not submitted.
** Form Code**
<form wire:submit.prevent="createAppointment">
<div class="modal-body">
<div class="form-group">
<label for="client_id">Client</label>
<select wire:model.defer="state.client_id" id="client_id" class="form-control">
#foreach($clients as $client)
<option value="{{$client->id}}">{{$client->name}}</option>
#endforeach
</select>
</div>
<div class="form-group">
<label for="">Date</label>
<div wire:ignore class="input-group date" id="datetimepicker4" data-target-input="nearest" data-appointmentdate = "#this">
<input type="text" class="form-control datetimepicker-input" id="appointmentDateInput" data-target="#datetimepicker4" />
<div class="input-group-append" data-target="#datetimepicker4" data-toggle="datetimepicker">
<div class="input-group-text"><i class="fa fa-calendar"></i></div>
</div>
</div>
</div>
<div class="form-group">
<label for="">Time</label>
<div class="input-group date" id="datetimepicker3" data-target-input="nearest" data-appointmenttime = "#this">
<input type="text" id="appointmentTimeInput" class="form-control datetimepicker-input" data-target="#datetimepicker3" />
<div class="input-group-append" data-target="#datetimepicker3" data-toggle="datetimepicker">
<div class="input-group-text"><i class="far fa-clock"></i></div>
</div>
</div>
</div>
<div class="form-group" wire:ignore>
<label for="note">Note</label>
<textarea wire.model.defer="state.note" id="note" class="form-control" cols="30" rows="4"></textarea>
</div>
</div>
<div class="modal-footer">
<button
type="button"
class="btn btn-secondary"
data-dismiss="modal"
>
<i class="mr-1 fa fa-times"></i>
Cancel
</button>
<button type="submit" id="submit" class="btn btn-primary">
<i class="mr-1 fa fa-save"></i>
{{ $showEditModal == true ? "Update" : "Save" }}
</button>
</div>
</form>
javascript Code
<script src="https://cdn.ckeditor.com/ckeditor5/29.2.0/classic/ckeditor.js"></script>
<script>
ClassicEditor
.create( document.querySelector( '#note' ) )
.then( editor => {
console.log( editor );
} )
.catch( error => {
console.error( error );
} );
</script>

Form submit using bootstrap modal without jquery and display event in calendar

I have successfully submitted form using bootstrap modal in laravel.Now I want to display the data in the calendar according to date.I have tried but unable to get the event in the calendar days.
event.blade.php
css
<link href="{{asset('admin-panel/assets/libs/fullcalendar/dist/fullcalendar.min.css')}}" rel="stylesheet" />
<link href="{{asset('admin-panel/assets/extra-libs/calendar/calendar.css')}}" rel="stylesheet" />
<link href="{{asset('admin-panel/dist/css/style.min.css')}}" rel="stylesheet">
<script src="{{asset('admin-panel/assets/libs/jquery/dist/jquery.min.js')}}"></script>
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="">
<div class="row">
<div class="col-lg-3 border-right p-r-0">
<div class="card-body border-bottom">
<h4 class="card-title m-t-10">Drag & Drop Event</h4>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-12">
<div id="calendar-events" class="">
<div class="calendar-events m-b-20" data-class="bg-info"><i class="fa fa-circle text-info m-r-10"></i>Event</div>
<div class="calendar-events m-b-20" data-class="bg-success"><i class="fa fa-circle text-success m-r-10"></i>Event</div>
<div class="calendar-events m-b-20" data-class="bg-danger"><i class="fa fa-circle text-danger m-r-10"></i>Event</div>
<div class="calendar-events m-b-20" data-class="bg-warning"><i class="fa fa-circle text-warning m-r-10"></i>Event</div>
</div>
<!-- checkbox -->
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="drop-remove">
<label class="custom-control-label" for="drop-remove">Remove after drop</label>
</div>
<a href="javascript:void(0)" data-toggle="modal" data-target="#add-new-event" class="btn m-t-20 btn-info btn-block waves-effect waves-light">
<i class="ti-plus"></i> Add New Event
</a>
</div>
</div>
</div>
</div>
<div class="col-lg-9">
<div class="card-body b-l calender-sidebar">
<div id="calendar"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- BEGIN MODAL -->
<div class="modal none-border" id="my-event">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title"><strong>Add Event</strong></h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body"></div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary waves-effect" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-success save-event waves-effect waves-light">Create event</button>
<button type="button" class="btn btn-danger delete-event waves-effect waves-light" data-dismiss="modal">Delete</button>
</div>
</div>
</div>
</div>
<!-- Modal Add Category -->
<div class="modal fade none-border" id="add-new-event">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title"><strong>Add</strong> Event</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<form action="{{route('event.store')}}" method="post">
#csrf
<div class="modal-body">
<div class="row">
<div class="col-md-6">
<label class="control-label">Date</label>
<input class="form-control form-white" name="date" type="date"/>
</div>
<div class="col-md-6">
<label class="control-label">Event Name</label>
<input class="form-control form-white" name="event" placeholder="Enter name" type="text"/>
<br>
</div>
<div class="col-md-12">
<label class="control-label">Description</label>
<input class="form-control form-white" name="description" placeholder="Enter description" type="text"/>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-danger waves-effect waves-light save-category">Save</button>
<button type="button" class="btn btn-secondary waves-effect" data-dismiss="modal">Close</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
javascript
#section('js')
<script src="{{asset('admin-panel/assets/libs/jquery/dist/jquery.min.js')}}"></script>
<script src="{{asset('admin-panel/dist/js/jquery-ui.min.js')}}"></script>
<script src="{{asset('admin-panel/assets/libs/bootstrap/dist/js/bootstrap.min.js')}}"></script>
<script src="{{asset('admin-panel/dist/js/custom.min.js')}}"></script>
<script src="{{asset('admin-panel/assets/libs/moment/min/moment.min.js')}}"></script>
<script src="{{asset('admin-panel/assets/libs/fullcalendar/dist/fullcalendar.min.js')}}"></script>
<script src="{{asset('admin-panel/dist/js/pages/calendar/cal-init.js')}}"></script>
#endsection
EventController.php
public function event()
{
$events=$this->getEventbyMonth(date('m'));
// dd($events);
return view('admin.calendar.event',compact('events'));
}
public function store(Request $request)
{
// dd($request->all);
$request -> validate([
'date' => 'required',
'event' => 'required',
]);
$event = new Event();
$event -> date = $request -> date;
$event -> event = $request -> event;
$event -> description = $request -> description;
$event ->save();
return redirect()->route('event');
}
private function getEventbyMonth($month)
{
return Event::whereMonth('date',$month)->get();
}
and my route look like this:
Route::get('event', ['as'=>'event', 'uses' => 'EventController#event']);
Route::post('event/store, ', ['as'=>'event.store', 'uses' => 'EventController#store']);
Expected results:
Imgur
Actual results:
Imgur
Database:
Imgur
Event form after clicking add new event
Imgur

how to manage the conflict between the Ajax handler and the form's action on octobercms

I would like to put the data of a form into a session
The action of the form depends on the choice made in the buttons .bien especially in the onclick() function .
for that I made this code:
title = "formulaire_commun_1"
url = "/formulaire_commun_1"
layout = "sidebar_layout"
is_hidden = 0
==
<?php
function onStart()
{
$this['transaction'] = Session::get('transaction');
$this['bien'] = Session::get('type_bien');
}
function onTest()
{
Session::put('transaction', input('TYPE_transaction'));
Session::put('type_bien', input('radio_type_bien'));
}
function onRedirectMe()
{
return Redirect::to('http://google.com');
}
?>
==
<ul class="progressbar">
<li class="active">transaction</li>
<li>details</li>
<li>confirmation</li>
</ul>
<br><br><br><br>
<form method="POST" data-request="onTest" data-request-success="onRedirectMe" name="formu" accept-charset="UTF8" enctype="multipart/form-data">
<input type="hidden" name="_handler" value="onUpdate">
{{form_token()}}
{{form_sessionkey()}}
<div class="form-group">
<label for="TYPE_transaction" class="col-sm-3">type de transaction:</label>
<div class="col-sm-9">
<select class="form-control" id="TYPE_transaction" name="TYPE_transaction">
<option>vendre</option>
<option>louer</option>
</select>
</div>
<br><br><br>
<p>choisissez un type de bien:</p>
<br><br>
<div class="col-sm-offset-2 col-sm-2">
<button class="btn btn-default bien" onclick="type_bien(0)" >
<img src="{{ 'assets/img/icones/icone_maison.png'|theme }}">
</button>
</div>
<div class="col-sm-offset-2 col-sm-2">
<button class="btn btn-default bien" onclick="type_bien(1)"><img src="{{ 'assets/img/icones/icone_villa.jpg'|theme }}"></button>
</div>
<div class="col-sm-offset-2 col-sm-2">
<button class="btn btn-default bien" onclick="type_bien(2)"><img src="{{ 'assets/img/icones/icone_riad.jpg'|theme }}"></button>
</div>
<br><br><br><br><br>
<div class="col-sm-offset-2 col-sm-2">
<button class="btn btn-default bien" onclick="type_bien(3)"><img src="{{ 'assets/img/icones/icone_appartement.png'|theme }}"></button>
</div>
<div class="col-sm-offset-2 col-sm-2">
<button class="btn btn-default bien" onclick="type_bien(4)"><img src="{{ 'assets/img/icones/icone_ferme.png'|theme }}"></button>
</div>
<div class="col-sm-offset-2 col-sm-2">
<button class="btn btn-defaul bien" onclick="type_bien(5)"><img src="{{ 'assets/img/icones/icone_magasin.jpg'|theme }}"></button>
</div>
<br><br><br><br>
<div style="display: none;">
<div class="radio" >
<label><input type="radio" name="radio_type_bien" id=0 value="maison" ></label>
</div>
<div class="radio" >
<label><input type="radio" name="radio_type_bien" id=1 value="villa"></label>
</div>
<div class="radio" >
<label><input type="radio" name="radio_type_bien" id=2 value="riad" ></label>
</div>
<div class="radio" >
<label><input type="radio" name="radio_type_bien" id=3 value="appartement" ></label>
</div>
<div class="radio" >
<label><input type="radio" name="radio_type_bien" id=4 value="formulaire_appartement" ></label>
</div>
<div class="radio" >
<label><input type="radio" name="radio_type_bien" id=5 value="magasin" ></label>
</div>
</div>
<br><br><br><br><br><br
<div class=" col-sm-offset-3 col-sm-9">
<button type="submit" class="btn btn-default">Register</button>
</div></div>
</form>
<script type = "text/javascript">
$(function() {
var $buttonBien = $('.bien');
$buttonBien.on('click',function (event) {
event.preventDefault();
});
});
function type_bien(x){
switch( x) {
case 0:
document.getElementById(0).checked="true";
document.forms["formu"].action="formulaire_villa";
break;
case 1:
document.getElementById(1).checked="true";
document.forms["formu"].action="formulaire_villa";
break;
case 2:
document.getElementById(2).checked="true";
document.forms["formu"].action="formulaie_riad";
break;
case 3:
document.getElementById(3).checked="true";
document.forms["formu"].action="formulaire_appartement";
break;
case 4:
document.getElementById(4).checked="true";
break;
case 5:
document.getElementById(5).checked="true";
break;
default:
alert('local_commerce est selected');
}
}
</script>
_____________
but unfortunately there is a conflict between ajax and the form
if i put data-request = "onTest" action = "" for example
I have no redirection
so I need a way to redirect the form to another page after the submit:
please help me
thank you in advance

how and where to record data in a session on octobercms

I would like to record the data of a form in a session
I find in the documentation that I have to use: Session::put('key', 'value');
but I do not know where to place this piece of code.
knowing that my form is located in the form_commun_1.htm page.
this is all the page :
title = "formulaire_commun_1"
url = "/formulaire_commun_1"
layout = "sidebar_layout"
is_hidden = 0
==
<ul class="progressbar">
<li class="active">transaction</li>
<li>details</li>
<li>confirmation</li>
</ul>
<br><br><br><br>
<form method="POST" action="" name="formu" accept-charset="UTF8" enctype="multipart/form-data">
<input type="hidden" name="_handler" value="onUpdate">
{{form_token()}}
{{form_sessionkey()}}
<div class="form-group">
<label for="TYPE_transaction" class="col-sm-3">type de transaction:</label>
<div class="col-sm-9">
<select class="form-control" id="TYPE_transaction">
<option>vendre</option>
<option>louer</option>
</select>
</div>
<br><br><br>
<p>choisissez un type de bien:</p>
<br><br>
<div class="col-sm-offset-2 col-sm-2">
<button class="btn btn-default" onclick="type_bien(0)"><img src="{{ 'assets/img/icones/icone_maison.png'|theme }}"></button>
</div>
<div class="col-sm-offset-2 col-sm-2">
<button class="btn btn-default" onclick="type_bien(1)"><img src="{{ 'assets/img/icones/icone_villa.jpg'|theme }}"></button>
</div>
<div class="col-sm-offset-2 col-sm-2">
<button class="btn btn-default" onclick="type_bien(2)"><img src="{{ 'assets/img/icones/icone_riad.jpg'|theme }}"></button>
</div>
<br><br><br><br><br>
<div class="col-sm-offset-2 col-sm-2">
<button class="btn btn-default" onclick="type_bien(3)"><img src="{{ 'assets/img/icones/icone_appartement.png'|theme }}"></button>
</div>
<div class="col-sm-offset-2 col-sm-2">
<button class="btn btn-default" onclick="type_bien(4)"><img src="{{ 'assets/img/icones/icone_ferme.png'|theme }}"></button>
</div>
<div class="col-sm-offset-2 col-sm-2">
<button class="btn btn-default" onclick="type_bien(5)"><img src="{{ 'assets/img/icones/icone_magasin.jpg'|theme }}"></button>
</div>
<br><br><br><br>
<div class="radio" style="display: none;" >
<label><input type="radio" name="radio_type_bien" id=0 value="maison" ></label>
</div>
<div class="radio" >
<label><input type="radio" name="radio_type_bien" id=1 value="villa"></label>
</div>
<div class="radio" >
<label><input type="radio" name="radio_type_bien" id=2 value="riad" ></label>
</div>
<div class="radio" >
<label><input type="radio" name="radio_type_bien" id=3 value="appartement" ></label>
</div>
<div class="radio" >
<label><input type="radio" name="radio_type_bien" id=4 value="formulaire_appartement" ></label>
</div>
<div class="radio" >
<label><input type="radio" name="radio_type_bien" id=5 value="magasin" ></label>
</div>
<br><br><br><br><br><br
<div class=" col-sm-offset-3 col-sm-9">
<button type="submit" class="btn btn-default">Register</button>
</div></div>
</form>
<script type = "text/javascript">
function type_bien(x){
switch( x) {
case 0:
document.getElementById(0).checked="true";
document.forms["formu"].action="formulaire_villa";
break;
case 1:
document.getElementById(1).checked="true";
document.forms["formu"].action="formulaire_villa";
break;
case 2:
document.getElementById(2).checked="true";
document.forms["formu"].action="formulaie_riad";
break;
case 3:
document.getElementById(3).checked="true";
document.forms["formu"].action="formulaire_appartement";
break;
case 4:
document.getElementById(4).checked="true";
break;
case 5:
document.getElementById(5).checked="true";
break;
default:
alert('local_commerce est selected');
}
}
</script>
do I have to go through creating a plugin or component ?
and where to put the session and how to use it?
please help?thank you
I would recommend creating a plugin and component, but this isn't 100% necessary in your case.
Here would be a basic self-contained page that would do what you are requesting:
title = "test"
url = "/test"
layout = "default"
is_hidden = 0
==
<?php
function onStart()
{
$this['example'] = Session::get('example-key');
}
function onTest()
{
Session::put('example-key', input('my-input'));
}
?>
==
<form data-request="onTest" data-request-success="location.reload();">
<input type="text" name="my-input">
<button type="submit">Submit</button>
</form>
{% if example %}
<strong>Example: {{ example }}</strong>
{% endif %}
I would recommend reading through the OctoberCMS documentation, it is excellent.

Update method laravel using modal box

My update method is working unfortunately it always updates the wrong data in this case it always updates the last data in my db list. I believe this occurs because my modal box directs to $user->id which always points to the last id as I have a for loop used at the top, is there a ways I could do to point it to the selected id instead?
view.blade.php
<div class="well col-xs-9 col-sm-9 col-md-9 col-lg-9 col-xs-offset-1 col-sm-offset-1 col-md-offset-1 col-lg-offset-1">
#foreach ($users as $user)
<div class="row user-row">
<!--div class="col-xs-3 col-sm-2 col-md-1 col-lg-1">
<img class="img-circle"
src="https://lh5.googleusercontent.com/-b0-k99FZlyE/AAAAAAAAAAI/AAAAAAAAAAA/eu7opA4byxI/photo.jpg?sz=50"
alt="User Pic">
</div-->
<div class="col-xs-2 col-sm-3 col-md-4 col-lg-4">
<h5 style="font-weight: bold">{{ $user->name }}</h5>
</div>
<div class="col-xs-8 col-sm-8 col-md-8 col-lg-8 dropdown-user" data-for=".{{ $user->id }}">
<h5 class="glyphicon glyphicon-chevron-down text-muted pull-right"> </h5>
</div>
</div>
<div class="row user-infos {{ $user->id }}">
<div class="col-xs-12 col-sm-12 col-md-10 col-lg-10 col-xs-offset-0 col-sm-offset-0 col-md-offset-1 col-lg-offset-1">
<div class="panel panel-info">
<div class="panel-heading">
<h2 class="panel-title">User Information</h2>
</div>
<div class="panel-body">
<div class="row">
<div class=" col-md-10 col-lg-10 hidden-xs hidden-sm">
<div class="col-xs-5">User level:</div><div class="col-xs-5"> {{ $user->role->role_description }}</div>
<div class="col-xs-5">Email:</div> <div class="col-xs-5"> {{ $user->email }}</div>
<div class="col-xs-5">Phone number: </div> <div class="col-xs-5"> {{ $user->mobile }} </div>
<div class="col-xs-5">Office extension: </div> <div class="col-xs-5"> [ TO IMPLEMENT ]</div>
</div>
</div>
</div>
<div class="panel-footer">
<button class="btn btn-sm btn-warning" type="button"
data-toggle="modal" data-target="#form">Edit <i class="glyphicon glyphicon-edit"></i></button>
<span class="pull-right">
<button class="btn btn-sm btn-danger" type="button">Inactive <i class="glyphicon glyphicon-remove"></i></button>
</span>
</div>
</div>
</div>
</div>
#endforeach
</div>
#if(Session::has('flash_message'))
<div class="alert alert-success col-xs-9 col-sm-9 col-md-9 col-lg-9 col-xs-offset-1 col-sm-offset-1 col-md-offset-1 col-lg-offset-1">
{{ Session::get('flash_message') }}
</div>
#endif
<div class="col-sm-offset-1 col-sm-2">
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-md" data-toggle="modal" data-target="#form">Register New User</button>
<!-- Modal -->
<div id="form" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">User Information</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" role="form" action="/manage_accounts/{{ $user->id }}" novalidate>
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group">
<label class="control-label col-sm-3" for="name">Username:</label>
<div class="col-sm-5 #if ($errors->has('name')) has-error #endif">
<input type="text" class="form-control" type="hidden" id="name" name="name" placeholder="Enter username">
#if ($errors->has('name')) <p class="help-block">{{ $errors->first('name') }}</p> #endif
</div>
</div>
...
Your modal is referencing the $user object, but it is outside of your foreach loop.
Specifically this line:
<form class="form-horizontal" role="form" action="/manage_accounts/{{ $user->id }}" novalidate>
You could register an onClick event for the modal pop-up button, that grabs a hidden input field of an user's id and dynamically updating the the action URL. Alternatively, you could just have the action URL be the same and handle the logic server side. This approach would have a hidden input field for the user ID that you would be updating, but is a lot cleaner that dealing with URL structure.
Edit:
Javascript Example:
<script type="text-javascript">
$(function() {
$('.btn--edit').on('click', function() {
var formAction = $('.form-horizontal').attr('action').replace(/(?!.*/).*, '');
var userId = $(this).closest('[name=user_id]').val();
$('.form-horizontal').attr('action', formAction + '/' + userId);
});
});
</script>
This requires you to update your modal button with a class name of .btn--edit
<button class="btn btn-sm btn-warning btn--edit" type="button" data-toggle="modal" data-target="#form">Edit <i class="glyphicon glyphicon-edit"></i></button>
This also requires you add a hidden input within the foreach somewhere. I chose after the user-infos class.
<input type="hidden" name="user_id" value="{{ $user->id }}" />
So here's how I got my update method to work.
<form class="form-horizontal" role="form" method="POST" action="/manage_accounts/" novalidate>
<input type="hidden" name="_method" value="PUT">
Javascript:
<script type="text/javascript">
$(function() {
$('.btn--edit').on('click', function(e) {
var userId = $(this).attr('data-for');
var formAction = "/manage_accounts/" + userId;
$('.form-horizontal').attr('action', formAction);
});
</script>
The modal button with class name of .btn--edit,
<button class="btn btn-sm btn-warning btn--edit" type="button"
data-toggle="modal" data-target="#update" data-for="{{$user->id}}">Edit <i class="glyphicon glyphicon-edit"></i></button>

Resources