Reputation: 322
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>
Upvotes: 0
Views: 1725
Reputation: 5149
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.
Upvotes: 2