TokenMismatchException for particular post url Hi , I am using laravel 5.3 , i face TokenMismatchException error in particular url post method but working fine other all post method . i confusing about what happened my project.
can you post the code for the form leading to this issue?
@mushood In blade.php
@if($mode=='add')
<form class="form-horizontal" role="form" action="/customattributevalue/add" method="post">
@elseif($mode=='edit')
<form class="form-horizontal" role="form" action="/customattributevalue/edit" method="post">
@endif
<div class="form-group">
<label for="custom_attribute_name" class="col-sm-2 control-label">Custom Attribute Name</label>
<div class="col-sm-10">
<select class="form-control" id="custom_attribute_id" name="custom_attribute_id">
@foreach($custom_attributes as $custom_attribute)
@if($mode=='add')
<option value="{{ $custom_attribute->custom_attribute_id }}">
@elseif($mode=='edit')
<option value="{{ $custom_attribute->custom_attribute_id }}" @if($custom_attribute->custom_attribute_id==$custom_attribute_value->custom_attribute_id) selected @endif>
@endif
{{ $custom_attribute->custom_attribute_name }}</option>
@endforeach
</select>
</div>
</div>
<div class="form-group">
<label for="custom_attribute_value" class="col-sm-2 control-label">Custom Attribute Value</label>
<div class="col-sm-10">
@if($mode=='add')
<input type="text" class="form-control" id="custom_attribute_value" name="custom_attribute_value" value="" placeholder="Custom Attribute Value" maxlength="255"/>
@elseif($mode=='edit')
<input type="hidden" name="_token" value="{{ csrf_token() }}"/>
<input type="hidden" name="custom_attribute_value_id" value="{{ $custom_attribute_value->custom_attribute_value_id }}"/>
<input type="text" class="form-control" id="custom_attribute_value" name="custom_attribute_value" maxlength="255" value="{{ $custom_attribute_value->custom_attribute_value }}"/>
@endif
</div>
</div>
<div class="form-group">
<label for="custom_attribute_value_code" class="col-sm-2 control-label">Custom Attribute Value Code</label>
<div class="col-sm-10">
@if($mode=='add')
<input type="text" class="form-control" id="custom_attribute_value_code" maxlength="2" name="custom_attribute_value_code" placeholder="Custom Attribute Value Code"/>
@elseif($mode=='edit')
<input type="text" class="form-control" id="custom_attribute_value_code" name="custom_attribute_value_code" placeholder="Custom Attribute Value Code" value="{{ $custom_attribute_value->custom_attribute_value_code }}" maxlength="2" readonly/>
@endif
</div>
</div>
<div class="form-group">
<label for="custom_attribute_sizechart_value" class="col-sm-2 control-label">IND Custom Attribute Sizechart Value</label>
<div class="col-sm-10">
@if($mode=='add')
<input type="text" class="form-control" id="custom_attribute_sizechart_value" name="custom_attribute_sizechart_value" placeholder="IND Custom Attribute Sizechart Value"/>
@elseif($mode=='edit')
<input type="text" class="form-control" id="custom_attribute_sizechart_value" name="custom_attribute_sizechart_value" placeholder="IND Custom Attribute Sizechart Value" value="{{ $custom_attribute_value->custom_attribute_sizechart_value }}"/>
@endif
</div>
</div>
<div class="form-group">
<label for="USA_custom_attribute_sizechart_value" class="col-sm-2 control-label">USA Custom Attribute Sizechart Value</label>
<div class="col-sm-10">
@if($mode=='add')
<input type="text" class="form-control" id="USA_custom_attribute_sizechart_value" name="USA_custom_attribute_sizechart_value" placeholder="USA Custom Attribute Sizechart Value"/>
@elseif($mode=='edit')
<input type="text" class="form-control" id="USA_custom_attribute_sizechart_value" name="USA_custom_attribute_sizechart_value" placeholder="USA Custom Attribute Sizechart Value" value="{{ $custom_attribute_value->custom_attribute_us_sizechart_value}}"/>
@endif
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Save Custom Attribute Value</button>
</div>
</div>
</form>
and in controller
public function addCustomAttributeValueGet(Request $request)
{
$custom_attributes = CustomAttributeMaster::getList();
$header = View::make('header', [])->render();
$footer = View::make('footer', [])->render();
$sidebar = View::make('sidebar', [])->render();
$body = View::make(
'masters.customattributevalue.detail',
[
'sidebar'=>$sidebar,
'mode'=>'add',
'custom_attributes' => $custom_attributes
]
)->render();
return response($header.$body.$footer);
}
From here
@elseif($mode=='edit')
<input type="hidden" name="_token" value="{{ csrf_token() }}"/>
It means that only the mode is edit that you have the csrf token. When the mode is add, you dont have it.
So at the top itself, i would do this
@if($mode=='add')
<form class="form-horizontal" role="form" action="/customattributevalue/add" method="post">
@elseif($mode=='edit')
<form class="form-horizontal" role="form" action="/customattributevalue/edit" method="post">
@endif
<input type="hidden" name="_token" value="{{ csrf_token() }}"/>
//form continues
Thanks a lot @mushood how do i miss that ???
Please sign in or create an account to participate in this conversation.