My current form only inputs an ISBN and the logged in user's id. It also allows for blank rows in the form. I'm trying to figure out how to also add a field for the title, but I can't get anything to work. I'm guessing that it has to be done as an array, but all the examples that I find online aren't working for me and each example seems to be using different methods. This is my current form without the title field that I'd like to add. Any help or input would be seriously appreciated
Form:
<form action='wanted' method='POST'>
<div class='form-group'>
<table>
<tr>
<td style="padding-bottom: 3px">
<input type="text" name="isbn[]" placeholder="enter isbn...">
</td>
</tr>
<tr>
<td style="padding-bottom: 3px">
<input type="text" name="isbn[]" placeholder="enter isbn...">
</td>
</tr>
<tr>
<td style="padding-bottom: 3px">
<input type="text" name="isbn[]" placeholder="enter isbn...">
</td>
</tr>
<tr>
<td style="padding-bottom: 3px">
<input type="text" name="isbn[]" placeholder="enter isbn...">
</td>
</tr>
<tr>
<td style="padding-bottom: 3px">
<input type="text" name="isbn[]" placeholder="enter isbn...">
</td>
</tr>
<input type="hidden" name="_token" value="">
</table>
<button type="submit" id="submit" class="btn btn-default">Add books</button>
</div>
Here's my controller:
public function wanted(Request $request)
{
$uid = Auth::user()->id;
$booklist = Input::get('isbn');
foreach($booklist as $onebook) {
if(is_null($onebook)) continue;
DB::table('wantedbooks')->insert(['isbn' => $onebook, 'user_id' => $uid]);
}
return view("bookswantedsubmitted");
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire