Error TokenMismatchException in VerifyCsrfToken.php line 68: - sql

I want to do multiple edit, I want to edit from the data I checked following script .blade, I found the TokenMismatchException error in VerifyCsrfToken.php line 68: when updating.
<form name="form" action="{{url('/update-kb')}}" method="post" onsubmit="return deleteConfirm();"/>
<div class="table table-responsive">
<table id="example1" class="table table-bordered">
<thead>
<tr class="info">
<th width="3%"><input type="checkbox" name="select_all" id="select_all" value=""/></th>
<th>No</th>
<th>Data lengkap</th>
<th>Aksi</th>
</tr>
</thead>
<tbody>
<?php $i = 1; ?>
#foreach( $datasiswa as $row )
<tr>
<td>
<label class="checkbox-inline"><input type="checkbox" name="checked_id[]" class="checkbox" value="{{$row->id}}"/>
</label>
</td>
<td width="5%">{{ $i }}</td>
<td width="95%">
<table class="table">
<tr>
<td class="info">Nama panggilan</td>
<td>{{$row->nm_panggilan}}</td>
<td class="warning">Pekerjaan ibu</td>
<td>{{$row->pekerjaan_ibu}}</td>
</tr>
<tr>
<td class="info">Jenis kelamin</td>
<td>{{$row->jenis_kelamin}}</td>
<td class="warning">No. Handphone</td>
<td>{{$row->hp_ibu}}</td>
</tr>
<tr>
<td class="info">Tempat, Tanggal lahir</td>
<td>{{$row->tempat}}, {{$row->tanggal_lahir}}</td>
<td class="warning">Alamat</td>
<td>{{$row->alamat}}</td>
</tr>
<tr>
<td class="info">Status anak</td>
<td>{{$row->status_anak}}</td>
<td class="warning">Golongan darah</td>
<td>{{$row->goldar}}</td>
</tr>
<tr>
<td class="info">Agama</td>
<td>{{$row->agama}}</td>
<td class="warning">Nama wali</td>
<td>{{$row->nm_wali}}</td>
</tr>
<tr>
<td class="info">Kewarganegaraan</td>
<td>{{$row->kewarganegaraan}}</td>
</tr>
<tr>
<td class="info">Anak ke-</td>
<td>{{$row->anak_ke}}</td>
</tr>
<tr>
<td class="info">Kelas</td>
<td>{{$row->kelas}}</td>
</tr>
</table>
</td>
<td>
<a href="{!! url('/'.$row->id.'/edit-siswa') !!}">
<button class="btn btn-default btn-block"><i class="fa fa-edit"></i></button><br>
</a>
<a href="{!! url('/'.$row->id.'/delete-siswa') !!}">
<button class="btn btn-danger btn-block"><i class="fa fa-trash"></i></button>
</a>
</td>
</td>
</tr>
<?php $i++; ?>
#endforeach
</tbody>
</table>
<div class="col-md-3">
<input type="submit" class="btn btn-danger" name="delete_submit" value="Hapus"/>
</div>
</div>
</form>
But I still have error, what causes it?
public function updatekb($id, Request $request)
{
$data = Datasiswa::find($id);
if (isset($request->delete_submit)) {
$idArr = $request->checked_id;
foreach ($idArr as $id) {
DB::update('update tb_siswa, tb_pernyataan set tb_pernyataan.kelas = "cekcek" where tb_pernyataan.kelas = "TK A" and tb_siswa.sekolah = "KB TK KHALIFAH 25" and id = "' . $id . '" ');
}
return back();
Session::flash('sukses', 'Data berhasil di update', compact('data'));
}
}

Add below to your form element.
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
Some answers are suggesting to disable csrf protection which is possible but NOT RECOMENDED. This leaves your application vulnureable.

Laravel use CSRF token to verify user request. so you have to use it on yevery request if you want to disable it then you can disable it from See here how to disable it or you can use it as
{{ csrf_field() }}
or
<input type="hidden" name="_token" value="{{ csrf_token() }}"/>

You can resolve this issue in two ways:-
First One:-
{{ csrf_field() }}
or
<input type="hidden" name="_token" value="{{ csrf_token() }}"/> // add this in form
Or the other (simpler) way, inside your app\Http\Middleware/VerifyCsrfToken.php add
protected $except = [
'update-kb', // your route name
];
Hope it helps!

Related

how to pass data from my controller to the view in laravel 8

am trying to retrieve data from the controller and send it through and email to student but it not working .i have tried it but it not going
public function test(){
$welcome = DB::table('results')
->select('studentinfos_id','marks','subject_code','name','email','rollid','classname','classnumber','image_path')
->join('studentinfos','studentinfos.id','=','results.studentinfos_id')
->join('subjects','subjects.id','=','results.subjects_id')
->join('addclasses','addclasses.id','=','results.addclasses_id')
->where('studentinfos.id',1)
->orderBy('subject_code','ASC')
->get();
Mail::to('serge#gmaile','divine')->cc('leade#gmail')->send(new mytestmail($welcome));
echo 'check ur inbox';
}
how do i get all the result from the $welcome in my view.blade.php
i was hopping that i will send and email that contains student info and result of there marks and subject through email
<div class="container">
<div class="text-center">
<h1> Result for {{ $classname }} student </h1>
</div>
<div class="border bg-white seespace p-3">
<div class="row">
<div class="col-md-8">
<table class="table table-borderless">
<tr>
<th>CLASS</th>
<td>{{ $welcome->classname }} {{ $welcome->classnumber }}</td>
</tr>
<tr>
<th>FULL NAME</th>
<td>: {{ $welcome->name }}</td>
</tr>
<tr>
<th>EMAIL</th>
<td>: {{ $welcome->email }}</td>
</tr>
<tr>
<th>ENROLLMENT</th>
<td>: {{ $welcome->enrollment }}</td>
</tr>
</table>
</div>
<div class="col-md-4">
<img class=" imgreport center" src="{{ asset('images/' . $welcome->image) }}"
alt="Card image cap">
</div>
</div>
<nav class="bg-dark text-white-50 mb-5">
<div class="container">
<div class="row p-3">
</div>
</div>
</nav>
<table class="table text-center table-bordered table-responsive py-3">
<thead class="thead-info text-center">
<tr>
<th>no</th>
<th>subject</th>
<th>marks</th>
</tr>
</thead>
<tbody>
<?php $num=1;
$total = 0;
$name;
?>
#foreach($welcome as $see)
<tr>
<td>{{ $num++ }}</td>
<td>{{ $see->subject_code }}</td>
<td>{{ $see->marks }}</td>
</tr>
<?php
$total += $see->marks ?>
#endforeach
<tr>
<td></td>
<td >total marks</td>
<td>{{ $total }}</td>
</tr>
<tr>
<td></td>
<td>Download</td>
<td>
<form action="/print" method="get">
<input type="hidden" value="{{$studnet}}" name='id' >
<button class="btn btn-info">Download</button>
</form>
</td>
</tr>
</tbody>
</table>
</div>
</div>
#stop
you have to pass the welcome variable to your view.
In the controller method add the data when displaying your view:
return view('view', ['welcome' => $welcome]);
https://laravel.com/docs/8.x/views#passing-data-to-views

How to pass value to model (Vuejs 3)

in my Vuejs3 project, there is a form in which the new row will be generated by pressing a button, so I put an array to handle new rows then I need to validate inputs, but after validation of the input of the array, the value didn't pass to model, but it works without the validation.. please help me to understand the mistake that I did.
The Form:
<table class="table table-stripped table-border">
<thead>
<tr>
<th>#</th>
<th style="width: 18%">
Medikament <span class="text-danger">*</span>
</th>
<th style="width: 9%">Milligram</th>
<th style="width: 9%">
Packung <span class="text-danger">*</span>
</th>
<th style="width: 7%">
Stück <span class="text-danger">*</span>
</th>
<th style="width: 19%">Apothekenname</th>
<th style="width: 24%">Adresse der Apotheke</th>
<th style="width: 14%">Postleitzahl</th>
</tr>
</thead>
<tbody>
<tr v-for="(item, index) in patientRequestForCreationDtos" :key="index">
<td>{{ index + 1 }}</td>
<td>
<input type="text" v-model="item.drugName" class="form-control" />
</td>
<td>
<input type="number" v-model="item.milligram" class="form-control" />
</td>
<td>
<input type="number" v-model="item.box" class="form-control" />
</td>
<td>
<input type="number" v-model="item.total" class="form-control" />
</td>
<td>
<input type="text" class="form-control" v-model="item.drugStoreName" :readonly="patientDetails.isElga == false" />
</td>
<td>
<input type="text" class="form-control" v-model="item.drugStoreAddress" :readonly="patientDetails.isElga == false" />
</td>
<td>
<input type="text" class="form-control" v-model="item.drugStorePostalCode" :readonly="patientDetails.isElga == false" />
</td>
<td>
<button type="button" #click="deleteRequestItemRow(index)" class="btn btn-sm btn-danger">
-
</button>
</td>
</tr>
</tbody>
</table>
The Array:
patientRequestForCreationDtos: [{
milligram: null,
box: null,
total: null,
drugStoreName: "",
drugStoreAddress: "",
drugStorePostalCode: "",
drugName: "",
}, ],
The validation function:
checkValidation() {
if (!this.patientRequestForCreationDtos.drugName) {
Swal.fire("drug name is required...");
return;
}
return true;
},
```js
---
it always says => drug name is required..
this.patientRequestForCreationDtos is array. maybe you can do this.
checkValidation(patientRequestForCreationDto) {
if (!patientRequestForCreationDto.drugName) {
Swal.fire("drug name is required...");
return;
}
return true;
},
if you'll have only one element in patientRequestForCreationDtos then you gotta choose first element in the array and then check its property
checkValidation() {
if (!this.patientRequestForCreationDtos[0].drugName) {
Swal.fire("drug name is required...");
return;
}
return true
},
also if your patientRequestForCreationDtos is always gonna be an array then you might find this helpful

Setting a Form Value in Vue Js

I am using Struts 1.x in my application. Recently i used Vue js.So, I use the same jsp page for Adding and updating (in this case company). So When i click edit, the details are fetched the page is redirected to that page and form values are set from the action class.
Here is the html portion
<form action="company.do" method="post" name="companyForm">
<html:hidden property="method" value="doAddUpdateCompany" />
<html:hidden property="companyId" value="${companyForm.companyId}" />
<div class="row" >
<div class="col-md-9">
<div class="grid simple">
<div class="grid-title ">
<h4>
<logic:equal value="addCompany" property="method" name="companyForm">
New <span class="semi-bold">Company</span>
</logic:equal>
<logic:equal value="updateCompany" property="method" name="companyForm">
Edit <span class="semi-bold">Company</span>
</logic:equal>
</h4>
<div class="tools"> </div>
</div>
<div class="grid-body">
<table class="tbl_wall" style="width: 100%" >
<tr >
<td class="fi_wall" >Company Name<span class="notify style16"> *</span></td>
<td class="fi_wall" ><html:text property="companyName" name="companyForm" styleClass="med_txt" /></td>
<td> </td>
</tr>
<tr>
<td class="fi_wall" valign="top" >Company Code<span class="notify style16"> *</span> (3 Letter)</td>
<td class="fi_wall" valign="middle" ><html:text property="companyCode" maxlength="3" styleClass="med_txt" name="companyForm" /></td>
<td> </td>
</tr>
<tr id="cmp">
<td class="fi_wall">Company Type </td>
<td class="fi_wall"><select name="companyType" v-model="companyType">
<option value="-1">select</option>
<option v-for=" result in results " v-bind:value="result.commonId">
{{ result.name}}</option>
</select></td>
</tr>
<tr>
<td colspan="3" align="center">
<button type="button" class="btn btn-success" onclick="doSave()" ><i class="fa fa-save"></i> Save</button>
</td>
</tr>
</table> </form>
and the vue Portion
<script type="text/javascript">
new Vue({
el: '#cmp',
data: {
results: [],
companyType : '-1'
},
mounted() {
axios.get('/easyoffice/companyType.do?method=getCompanyTypeAjax').then(response => {
this.results = response.data,
this.companyType = document.forms['companyForm'].companyType.value
})
.catch(e => {
this.errors.push(e)
})
}
});</script>
i used this.companyType = document.forms['companyForm'].companyType.value to set form value but it is not working. Any Thoughts?

POST request not working in form

I'm trying to submit some form using POST method. Here is par of form:
<form action="interlopers.php" mehod="post" id = "interlopersForm" name="interlopersForm" onsubmit="return validateInterlopersForm()">
<table border="0">
<tr>
<td> <label for="ast_num" > Ast. num </label> </td>
<td> <input type="text" name="ast_num" id = "ast_num"
value="<?php if(isset($_REQUEST['ast_num'])) { echo htmlentities ($_REQUEST['ast_num']); } ?>"
size="6"> </td>
</tr>
<tr>
<td><label for="cut_off"> Cut-off </label></td>
<td><input type="text" name="cut_off" id="cut_off" size="6" ></td>
</tr>
<tr>
<td><label for="data"> Data </label></td>
<td><input type ="checkbox" name="data" id = "dataSDSS" value="SDSS" checked> SDSS <br>
<input type ="checkbox" name="data" id="dataWISE" value="WISE" checked > WISE <br>
<input type ="checkbox" name="data" id = "dataSp" value="Sp" checked> Taxonomy</td>
</tr>
<tr>
<td> <label for="isFinalStep"> Just interlopers? </label> </td>
<td> <input type = "checkbox" name="isFinalStep" id = "isFinalStep"> </td>
</tr>
<tr> <input type="hidden" name="submitted" value="1"> </tr>
<tr>
<td colspan="2" align="center"> <input type="submit" value="Calculate" > </td>
</tr>
</table>
</form>
But, instead of getting POST request im getting GET request. I'm using apache server and php5 on Ubuntu. I tried this on local-server and on remote host, but still GET instead of POST.
Change mehod="post" to method="post".
You wrote wrong.

Multiple files upload in selenium webdiver

I want to upload 5 files,but my 'file input' is same name/id,how can i possible to upload five files.
My HTML code is:
<div>
<table id="listtable">
</table>
<br/>
<input type="hidden" name="delFiles" id="deletefiles"/>
<table id="filetable">
<tbody>
<tr>
<td>
<input type="file" size="27px" id="page" name="page"/>
</td>
<td>
<a href="#">
<img name="del" onclick="removeRow(this);" title="delete" alt="delete" src="images/user_delete.png"/>
</a>
</td>
</tr>
<tr>
<td>
<input type="file" size="27px" name="page"/>
</td>
<td>
<img name="del" onclick="removeRow(this);" title="delete" alt="delete" src="images/user_delete.png"/>
</td>
</tr>
<tr>
<td>
<input type="file" size="27px" name="page"/>
</td>
<td>
<img name="del" onclick="removeRow(this);" title="delete" alt="delete" src="images/user_delete.png"/>
</td>
</tr>
<tr>
<td>
<input type="file" size="27px" name="page"/>
</td>
<td>
<img name="del" onclick="removeRow(this);" title="delete" alt="delete" src="images/user_delete.png"/>
</td>
</tr>
<tr>
<td>
<input type="file" size="27px" name="page"/>
</td>
<td>
<img name="del" onclick="removeRow(this);" title="delete" alt="delete" src="images/user_delete.png"/>
</td>
</tr>
</tbody>
</table>
<br/>
<br/>
</div>
This works on Chrome:
driver.findElement(By.id("input1")).sendKeys("path/to/first/file-001 \n path/to/first/file-002 \n path/to/first/file-003");
You would do so the same as you would if you were only uploading one file.
driver.findElement(By.id("input1")).sendKeys("path/to/first/file");
driver.findElement(By.id("input2")).sendKeys("path/to/second/file");
driver.findElement(By.id("input3")).sendKeys("path/to/third/file");
driver.findElement(By.id("input4")).sendKeys("path/to/fourth/file");
driver.findElement(By.id("input5")).sendKeys("path/to/fifth/file");
driver.findElement(By.id("upload")).click();
Obviously, you'll need to put in your own correct IDs or whatever.
that easy
like
//input[#type="file"]
will point to the first input tag
and
(//input[#type="file"])[{INDEX}]
where INDEX is the number of the of the input tag
note: indexing in xpath starts from 1
OR you can use the
file_tag_list =driver.find_elements_by_xpath(//input[#type="file"])
function that the python syntax you can find it for different languages just google it.
this function will return a list of webdriver element
and then you can
file_tag_list[0].send_keys(filepath)
file_tag_list[1].send_keys(filepath)
Holy ##### it even works in PHP:
public function waitForAjax()
{
while(true)
{
$ajaxIsComplete = array(
'script' => 'return jQuery.active == 0',
'args' => array()
);
$ajaxIsComplete = $this->execute($ajaxIsComplete);
if ($ajaxIsComplete) {
break;
}
}
}
Thank you :)