0
我有以下形式,我想將數據發送到控制器。問題是來自動態創建的輸入的數據沒有傳遞給控制器。這是dd($request->all());
動態創建的輸入數據沒有傳遞到控制器
`array:4 [▼
"_token" => "gzpNTHPfZl8GCtNbCPGJrc4S4zTUmhhMUve4gyet"
"course" => "ICTP"
"section" => "BB3"
"lecture" => "functions and pointers"
]
`
`
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<META http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body>
<div>
@if(count($errors)>0)
<div class="alert alert-danger">
@foreach($errors->all() as $error)
<p>{{$error}}</p>
@endforeach
</div>
@endif
</div>
<div>
<form action="{{route('course.save')}}" method="post">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<label>Select a category</label>
<select>
<option>Category 1</option>
<option>Category 2</option>
<option>Category 3</option>
<option>Category 4</option>
</select>
<br><br>
<label>Select a subcategory</label>
<select>
<option>SubCategory 1</option>
<option>SubCategory 2</option>
<option>SubCategory 3</option>
<option>SubCategory 4</option>
</select>
<br><br>
<label for="course">Course Name:</label>
<input type="text" name="course" id="course"/>
<div id="content">
<div id="section-content-1">
<div id="secs">
<label for="section">Section 1:</label>
<input type="text" name="section" id="section"/>
</div>
<div id="lects">
<label for="lecture">Lecture 1:</label>
<input type="text" name="lecture" id="lecture"/>
</div>
<button type="button" id="add-lect" data-lect="1">Add New Lecture</button><br><br>
</div>
</div>
<button type="button" id="add-sect" data-sect="1" >Add New Section</button>
<br><br><br><br>
<button class="btn-primary" type="submit">Save</button>
</form>
</div>
</body>
</html>
<script src="{{asset('/js/code.js')}}"></script>`
這裏是jQuery的文件code.js
//$('#add-lect').click(function
$('#content').on('click', '#add-lect', function() {
var count = parseInt($(this).parent().children('#lects').children().length/2) + 1;
lectures = '<label>Lecture ' + count + ':</label><input type="text" name="lecture" id="lecture"/>'
$(this).parent().find('#lects').append(lectures);
});
$('#add-sect').click(function(){
sect_id = parseInt($('#add-sect').attr('data-sect')) + 1;
$('#add-sect').attr('data-sect', sect_id)
var count = ($("#secs").children().length/2) + 1;
//section = '<div id="section-content-'+sect_id+'"> <div id="secs"> <label for="section">Section'+sect_id+':</label><input type="text" name="section" id="section-"/></div><div id="lects"><label for="lecture">Lecture 1:</label><input type="text" name="lecture" id="lecture"/></div><button type="button" id="add-lect" data-lect="1">Add New Lecture</button<br><br></div>'
section = '<div id="section-content-'+sect_id+'"><div id="secs"><label for="section">Section '+sect_id+':</label> <input type="text" name="section" id="section"/></div><div id="lects"><label for="lecture">Lecture 1:</label><input type="text" name="lecture" id="lecture"/></div><button type="button" id="add-lect" data-lect="1">Add New Lecture</button><br><br></div>'
$('#content').append(section);
});
這不是'name ='講座'它應該是'name ='講座[]「' –
@u_mulder現在我正在講授講座的價值,謝謝。 – Amjad