I am developing a Laravel application using Laravel 5.7 and I have following problem:
I want to do something like this
<form method="post" action="/story/editorsubmit" enctype="multipart/form-data">
@csrf
<input type="hidden" name="fullobject" value={{ $req }}>
<button type="submit" name="submitButton" value="edit" class="btn btn-primary">Edit</button>
</form>
The data submitted from the form is what becomes the request. Also you were missing some quotes.
<form method="post" action="/story/editorsubmit" enctype="multipart/form-data">
@csrf
<input type="hidden" name="fullobject" value="{{ $req }}">
<button type="submit" name="submitButton" value="edit" class="btn btn-primary">Edit</button>
</form>
Your current data could be accessed in the controller on form submit using the name of the submitted property. But I doubt this would work as $req is an object, not a string.
$object = request('fullobject');
But ideally, you should be defining the properties separately. I'm assuming these hidden elements actually represent editable form inputs? If nothing is changing, it doesn't make sense to do it this way.
EDIT: Added way of dealing with arrays.
<form method="post" action="/story/editorsubmit" enctype="multipart/form-data">
@csrf
@foreach ($req->all() as $key => $value)
@if (is_array($value))
@foreach($value as $v)
<input type="hidden" name="{{ $key }}[]" value="{{ $v }}">
@endforeach
@else
<input type="hidden" name="{{ $key }}" value='{{ $value }}'>
@endif
@endforeach
<button type="submit" name="submitButton" value="edit" class="btn btn-primary">Edit</button>
</form>
Then the submitted request would contain the individual properties like before.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.