I use laravel 9 and i have a registration form and submit button for some reason doesn't work in mobile phone only, but its working fine in desktop. Any idea what wrong? Thankyou!
Html (blade):
<form action="{{ route('jokibukti') }}" method="POST">
#csrf
<td width="25%">{{ $item->keterangan }} <input type="text"
id="ketbaru" name="keteranganbaru" class="form-control"
placeholder="Masukan Bonus Disini!"></td>
{{-- <td width="7%"><a class="btn btn-primary btn-sm" onclick=''>Selesai</a> --}}
<td width="25%">
<input type="hidden" name="id" value="{{ $item->id }}">
<label class="">
<span class="sr-only">Pilih Gambar</span>
<input type="file" name="image" class="" />
#error('image')
<span class="text-red-600 text-sm">{{ $message }}</span>
#enderror
</label>
<button type="submit" value="submit" class="btn btn-primary btn-sm">Submit</button>
</form>
Route :
Route::post('/joki/bukti', [ControllerJoki::class, 'buktiselesai'])->name('jokibukti');
Controller :
public function buktiselesai(Request $request)
{
// #dd($request->image);
$this->validate($request, [
'image' => 'required|image|mimes:jpg,png,jpeg,gif,svg|max:2048',
]);
$ketbaru = $request->keteranganbaru;
$ketlamauser = Jokiongoing::where('id', $request->id)->first();
$ketlama = $ketlamauser->keterangan;
if ($ketlama != "") {
$keterangan = $ketlama . " & " . $ketbaru;
} else {
$keterangan = $ketbaru;
}
// $image_path = $request->file('image')->store('buktijoki', 'public');
$imageName = time() . '.' . $request->image->extension();
$request->image->move(public_path('buktijoki'), $imageName);
$data = Jokiongoing::where('id', $request->id)->update([
'bukti' => $imageName,
'keterangan' => $keterangan,
'acc' => '1',
]);
if ($data) {
return redirect()->route('jokiaktif')->with(['success' => 'Bukti Berhasil disimpan']);
} else {
return redirect()->route('jokiaktif')->with(['error' => 'Bukti Gagal Disimpan']);
}
}
<script>
var tap = true;
document.addEventListener('touchstart', function(e) {
tap = true;
});
document.addEventListener('touchmove', function(e) {
tap = false;
});
document.addEventListener('touchend', function(e) {
if (tap) {
//users tapped the screen
}
});
</script>
Trying adding this script from someone in the stackoverflow, but get nothing as result.
Im try to add onClick to the button
<button onClick = "testsubmit()" value="submit" class="btn btn-primary btn-sm">Submit</button>
<script>
function testsubmit() {
alert("masuk");
}
</script>
and its work fine, what happen to type="submit" ?
Related
In my Laravel-5.8 I have this code in the controller:
public function appraisal(Request $request)
{
try {
$userCompany = Auth::user()->company_id;
$userId = Auth::user()->id;
$company = OrgCompany::where('id', $userCompany)->first();
$identities = Identity::where('company_id', $userCompany)->pluck('appraisal_name','id');
$goals = AppraisalGoal::where('employee_id', $userId)
->where(function ($query) {
$query->where('is_approved', 3)->orWhere('is_visible', 0);
})
->whereNull('deleted_at')
->orderBy('goal_type_id');
$method = $request->method();
if ($request->isMethod('post')) {
$id = $request->input('identity_id');
if ($request->has('search')) {
// select search
if ($request->input('identity_id')) {
$goals->where('identity_id',$request->input('identity_id'));
}
$goals = $goals->get();
return view('appraisal-default',['goals' => $goals, 'identities' => $identities]);
} elseif ($request->has('viewIdentity')) {
// select goal identity
if ($request->input('identity_id')) {
return view('performance_dashboard', $id);
}
}
} else {
//select current year
$goals = $goals->get();
return view('appraisal-default',['goals' => $goals, 'identities' => $identities]);
}
} catch (Exception $exception) {
Log::error($exception);
Session::flash('error', 'Action failed! Please try again');
return back();
}
}
view blade: appraisal-default
<div class="row" style="margin-bottom: 10px">
<label class="control-label"> Performance Period:<span style="color:red;">*</span></label>
<div class="col-sm-8">
<select id="identity" name="identity_id" class="form-control">
<option value="">--- Select Performance Period ---</option>
#foreach ($identities as $ids => $name)
<option value="{{ $ids }}" {{ request( 'identity_id')==$ids ? 'selected' : ''}}>{{ $name }}</option>
#endforeach
</select>
</div>
<div class="col-xs-4">
<button type="submit" class="btn btn-primary btn-sm" name="search">Search</button>
<form action="{{ route('performance_dashboard', $id->id) }}" method="get" target="_blank" class="form-horizontal" enctype="multipart/form-data">
{{csrf_field()}}
<button type="submit" class="btn btn-secondary btn-sm" name="viewIdentity"><i class="fas fa-file-pdf"></i> View Identity</button>
</form>
</div>
</div>
In the view, I have two buttons with names: search and viewIdentity
When the
<select id="identity" name="identity_id" class="form-control">
is selected.
If search button is submitted, it displays the result on the same page. This is working.
However, where I'm having problem is when viewIdentity button is submitted. At this point it suppose to take the id of the dropdown as the parameter in:
<form action="{{ route('performance_dashboard', $id->id) }}" method="get" target="_blank" class="form-horizontal" enctype="multipart/form-data">
{{csrf_field()}}
<button type="submit" class="btn btn-secondary btn-sm" name="viewIdentity"><i class="fas fa-file-pdf"></i> View Identity</button>
</form>
and display the result in another page: performance_dashboard
I got this error in the view:
production.ERROR: Undefined variable: id
It points to this line in the view:
<form action="{{ route('performance_dashboard', $id->id) }}" method="get" target="_blank" class="form-horizontal" enctype="multipart/form-data">
How do I get it resolved?
Thanks
I wrote a small script that updates the information on the page when editing. Everything basically works as it should, but I just can’t update the image. I don’t understand what the matter is. Without a script, with a page reload, everything works as it should.
Ajax script
<script type="text/javascript">
$("document").ready(function() {
$("#editPostButton{{$post->id}}").click(function() {
var formData = $("#EditPostForm{{$post->id}}").serialize();
$.ajax({
url: "{{route('editPost', ['id' => $user->id, 'postId' => $post->id])}}",
type: "POST",
data: formData,
success: function(data) {
$("#textpostdata{{$post->id}}").html($(data).find("#textpostdata{{$post->id}}").html());
$("#closeButton{{$post->id}}").click();
}
});
});
});
</script>
My Controller
public function editPost(Request $request, $id, $postId) {
$validator = $this->validate($request,[
'title' => 'max:100',
'message' => 'max:5000',
'img' => 'mimes:jpeg,png,gif,jpg|max:5000',
'videoPost' => 'max:100'
]);
if($validator) {
$user = User::find($id);
if(!$user && $user != Auth::user()->id) {
return abort(404);
}
$post = Profile::find($postId);
if(!$post) {
return abort(404);
}
$post->user_id = Auth::user()->id;
$post->title = $request->title;
$post->message = $request->message;
$post->videoPost = str_replace('watch?v=', 'embed/', $request->videoPost);
if($request->file('img')) {
$path = Storage::putFile('public/'.Auth::user()->id.'/post', $request->file('img'));
$url = Storage::url($path);
$post->img = $url;
}
$post->update();
return redirect()->back();
}
}
And update form
<form action="{{route('editPost', ['id' => $user->id, 'postId' => $post->id])}}" method="post" enctype="multipart/form-data" id="EditPostForm{{$post->id}}" name="postForm">
#csrf #method('PATCH')
<div class="form-group">
<textarea maxlength="100" name="title" class="form-control" rows="1">{{$post->title}}</textarea>
</div>
<div class="form-group">
<textarea id="message" maxlength="5000" name="message" class="form-control" rows="10">{{$post->message}}</textarea>
</div>
<div class="form-group">
<textarea maxlength="100" class="form-control mt-1" id="videoPost" name="videoPost" cols="100" rows="1">{{$post->videoPost}}</textarea>
</div>
<h6>Current image</h6>
<img src="{{$post->img}}" class="img-fluid mb-2" width="230">
<div class="form-group">
<input type="file" id="img" name="img" accept="image/*">
</div>
<button type="button" class="btn btn-sm btn-primary" id="editPostButton{{$post->id}}">Edit</button>
</form>
partners from stackOverflow im making a module using laravel like backend, and vue.js by frontend, i have a form to create a new entity, but the controller dont get the values¡, plz help me to find the error. I'm going to share the code.
the routes.web
//new event from API
Route::resource('/api/events', 'EventsController', ['except' => 'show','create']);
The function in the controller EventsController.php
<?php
namespace soColfecar\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use soColfecar\Http\Requests\CreateEventRequest;
use soColfecar\Http\Requests\UpdateEventRequest;
use soColfecar\User;
use soColfecar\Change;
use soColfecar\Event;
use soColfecar\Event_type;
use Auth;
public function store(Request $request)
{
$exploded = explode(',', $request->banner);
$decoded = base64_decode($exploded[1]);
if(str_contains($exploded[0],'jpeg'))
$extension = 'jpg';
else
$extension = 'png';
$fileName = str_random().'.'.$extension;
$path = public_path().'/storage/banner/'.$fileName;
file_put_contents($path, $decoded);
Event::create([
'event' => strtoupper($request['event']),
'id_event_type' => $request['id_event_type'],
'date_init' => $request['date_init'],
'date_end' => $request['date_end'],
//'banner' => $fileName,
]);
Change::create([
'description' => 'Creo el de evento:'.$request['event'].' correctamente.',
'id_item' => 10,
'id_user' => Auth::user()->id,
]);
return redirect()->route('events.index')
->with('info', 'evento guardado con exito');
}
the method:
<form method="POST" v-on:submit.prevent="storeNewEvent">
<div class="form-group m-form__group">
<label for="eventTypeInput">Tipo de vento:</label>
<v-select :options="eventTypes" v-model="newEvent.id_event_type" id="eventTypeInput">
<template slot="option" slot-scope="option">
{{ option.label }}
</template>
</v-select>
<span v-for="error in errors" class="text-danger" :key="error.error">{{ error.city_id }}</span>
</div>
<div class="form-group m-form__group">
<label for="inputHotelName">Nombre del Evento</label>
<input type="text" class="form-control" name="inputHotelName" v-model="newEvent.event" placeholder="Nombre del Evento">
<span v-for="error in errors" class="text-danger" :key="error.error">{{ error.hotel_name }}</span>
</div>
<div class="form-group m-form__group">
<label for="date_init_imput">Fecha de inicio</label>
<input class="form-control" type="date" v-model="newEvent.date_init" value="" id="date_init_imput">
</div>
<div class="form-group m-form__group">
<label for="date_end_imput">Fecha de finalizacion</label>
<input class="form-control" type="date" v-model="newEvent.date_end" value="" id="date_end_imput">
</div>
<div class="form-group m-form__group">
<label for="customFile">Banner del Evento</label>
<div></div>
<div class="custom-file">
<input type="file" class="custom-file-input" #change="getLogo" id="customFile">
<label class="custom-file-label" for="customFile">Seleccione archivo</label>
<span v-for="error in errors" class="text-danger" :key="error.error">{{ error.logo }}</span>
</div>
</div>
<hr>
<button type="submit" class="btn btn-info waves-effect text-left">Guardar</button>
</form>
data() {
return {
changes: [],
eventTypes: [],
errors: [],
newEvent: {
event: '',
id_event_type: '',
date_init: '',
date_end: '',
banner: '',
}
}
},
storeNewEvent : function() {
var url = 'api/events';
var newEvent = this.newEvent
axios.post(url, {event: this.newEvent}).then(response => {
this.newEvent = {}
this.errors = [];
$('#new_event_modal').modal('hide');
$('.modal-backdrop').remove();
toastr.success('Se ha creado el evento con exito!')
}).catch(error => {
this.errors = error.response.data
});
},
And the error
"Too few arguments to function soColfecar\Http\Controllers\EventsController::store(), 0 passed and exactly 1 expected"
enter image description here
You need to type hint the $request so Laravel knows to fill it in ("dependency injection").
At the top of your file:
use Illuminate\Http\Request;
Then, for your function:
public function store(Request $request) {
I tried to send an email to a user and arrived at Miltrap
Now I put all the users on my system (table users in database) and introduced them to checkboxs and I want to send one email to more than one user or to all users and I did not see the result on the mailtrap
This is the code
MailboxController.php
public function form(Request $request)
{
$users = User::where('id', '!=', auth()->user()->id)->get();
return view('MailBox.form',compact('users'));
}
public function contact(Request $request)
{
//$emails = [];
$this->validate($request, [
'email' => 'required|email',
'subject' => 'min:3',
'message' => 'min:10']);
$data = array(
'email' => $request->email,
'subject' => $request->subject,
'bodyMessage' => $request->message
);
Mail::send('MailBox.contact', $data, function($message) use ($data){
$message->from('info#dev-any.com');
$message->to($data['email']);
$message->subject($data['subject']);
});
Session::flash('success', 'Your Email was Sent!');
return redirect('/dashboard/mailbox');
}
Web.php
Route::get('/mailbox', 'MailboxController#form')->name('mailbox.form');
Route::post('/mailbox/contact', 'MailboxController#contact')->name('contact');
form.blade.php
<form action="{{ route('contact') }}" method="POST">
{{ csrf_field() }}
<div class='form-group col-md-6'><strong>Select User :</strong><br>
<input type="checkbox" id = "chckHead" name="chk_all" value="" onchange="checkall()" id='allcb' /><strong> Check All </strong> </br>
#foreach ($users as $user)
<tr>
<td><input type="checkbox" class = "chcktbl" onchange="check()" name="email" id="email" value={{ $user->id }}></td>
<td>{{ $user->name }}</td></br>
</tr>
#endforeach
</div>
<div class="form-group col-md-6">
<label name="subject">Subject:</label>
<input id="subject" name="subject" class="form-control">
</div>
<div class="form-group col-md-6">
<label name="message">Message:</label>
<textarea id="message" name="message" class="form-control">Type your message here...</textarea>
</div>
<input type="submit" value="Send Message" class="btn btn-success col-md-6">
</form>
</div>
</div>
<script type="text/javascript">
$('.chcktbl').click(function () {
var length = $('.chcktbl:checked').length;
if (length > 3) {
// alert(length);
$('.chcktbl:not(:checked)').attr('enable', true);
}
else {
$('.chcktbl:not(:checked)').attr('enable', false);
}
});
</script>
<script type="text/javascript">
$('#chckHead').click(function () {
if (this.checked == false) {
$('.chcktbl:checked').attr('checked', false);
}
else {
$('.chcktbl:not(:checked)').attr('checked', true);
}
});
$('#chckHead').click(function () {
});
Simply change the email checkbox, and modify the validation
<input type="checkbox" class="chcktbl" onchange="check()" name="email[]" id="email" value={{ $user->id }}>
I want to display data in textfield . Not all data. When search by name and it have data then went to display data in textfield. And search form and want to display form is same form.
<form action="postAuth" method="post" enctype="multipart/form-data">
<div class="input-group">
<input type="text" class="form-control" name="productname" placeholder="Search Product"> <span class="input-group-btn">
<button type="submit" class="btn btn-default" name="search">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
<div class="form-group">
<label for="ProductName" >Product Name :</label>
<input type="text" class="form-control" name="ProductName">
</div>
</form>
route
Route::post("postAuth", ['as' => 'search' , 'uses'=> 'ProductController#postAuth']);
That's my controller
public function postAuth(Request $request)
{
//check submit
$update = $request->get('update',false);
if($update){
return $this->update($request);
}
$productname = $request->input('productname');
$product = DB::table('products')
->where('product_name','LIKE','%'.$productname.'%')
->get();
if($product->count() > 0)
return redirect()->to('/update')->withDetails($product)->withQuery($productname);
else
$request->session()->flash('alert-danger','No Data Found!');
return redirect()->to('/update');
}
can anyone help me please
Here what you exactly want : Just for example
<div class="form-group">
{{Form::label('name', trans('admin.venue.fields.name'),['class' => 'col-md-4 control-label'])}}
<div class="col-md-6">
{{Form::text('name',old('name', isset($venue) ? $venue->name : ''),['class' => 'form-control'])}}
</div>
</div>
Model function example :
public function save(Request $request) {
try {
$this->validate($request, Venue::rules(), Venue::messages());
$venue = Venue::saveOrUpdate($request);
if($venue !== false) {
if($request->get('continue', false)) {
return redirect()->route('admin.venue.edit', ['id' => $venue->id])->with('success', trans('admin.venue.save_success'));
} else {
return redirect()->route('admin.venue.index')->with('success', trans('admin.venue.save_success'));
}
} else {
return back()->with('error', "Unable to save venue")->withInput();
}
} catch (\Exception $ex) {
return back()->with('error', "Unable to save venue")->withInput();
}
}
Hope it is useful.
use session() in the value field of ProductName input tag and with some logic, for example
view file:
#if(session()->has('data'))
#if(count(session('data')))
#foreach(session('data') as $data)
<input type="text" class="form-control" name="ProductName" value="{{ $data->prodcut_name }}">
#endforeach
#else
<input type="text" class="form-control" name="ProductName" value="No Data Available">
#endif
#else
<input type="text" class="form-control" name="ProductName">
#endif
and in Controller:
public function postAuth(Request $request) {
$productname = $request->input(productname);
$product_search = Products::where('product_name', $productname)->get();
if($product_search) {
return redirect()->back()->with('data', $product_search);
}
}