[英]Retrieve value from a table
I want to know the content of first td
tag in each tr
tag. 我想知道每个
tr
标签中第一个td
标签的内容。 The problem is I need to store the title of a file and the file name in the database without repeating the code for each chosen file. 问题是我需要在数据库中存储文件的标题和文件名,而不必为每个选定的文件重复代码。 I am trying to get the value of the
<td>
tag. 我正在尝试获取
<td>
标签的值。 I have written a code that shows to the user a table of two columns the first one is the file title, the second is a button to choose file So that user can upload multi files and send it by Send button at once. 我编写了一个代码,向用户显示一个两列的表,第一个是文件标题,第二个是选择文件的按钮,以便用户可以上传多个文件并通过“ 发送”按钮立即发送 。 To clarify the idea:
为了澄清这个想法:
This is my code: 这是我的代码:
<td>Course Report</td>
<td>@foreach ($temp1 as $fi)
@if($fi->title =="Course Report")
<form action="{{route('dele')}}" method="post" ><input type="hidden" name="_token" value="{{csrf_token()}} ">
<button id="delete-id" name="filename" value="{{$fi->id}}">delete </button>
@endif
@endforeach
@if($fi->title !="Course Report")
<form action="{{route('filestest')}}" method="post" enctype="multipart/form-data">
{{csrf_field()}}
<input id="file-id"type="file" name="file1"></input>
@endif
</td>
</tr>
<tr> <td>Sample of Midterm Exam Answer sheet – High</td>
<td>@foreach ($temp1 as $fi)
@if($fi->title =="Sample of Midterm Exam Answer sheet – High")
<form action="{{route('dele')}}" method="post" ><input type="hidden" name="_token" value="{{csrf_token()}} ">
<button id="delete-id" name="filename" value="{{$fi->id}}">delete </button>
@endif
@endforeach
@if($fi->title !="Sample of Midterm Exam Answer sheet – High")
<form action="{{route('filestest')}}" method="post" enctype="multipart/form-data">
{{csrf_field()}}
<input id="file-id"type="file" name="file2" ></input>
@endif
</td>
If you want to read data use input hidden tag. 如果要读取数据,请使用输入隐藏标签。 set data in hidden tag value too.
也在隐藏标签值中设置数据。 may be it solves your probelm.
可能是它解决了您的问题。
<td>Sample of Midterm Exam Answer sheet – High</td>
<td>@foreach ($temp1 as $fi)
@if($fi->title =="Sample of Midterm Exam Answer sheet – High")
<form action="{{route('dele')}}" method="post" ><input type="hidden" name="_token" value="{{csrf_token()}} ">
<button id="delete-id" name="filename" value="{{$fi->id}}">delete </button>
@endif
@endforeach
@if($fi->title !="Sample of Midterm Exam Answer sheet – High")
<form action="{{route('filestest')}}" method="post" enctype="multipart/form-data">
{{csrf_field()}}
<input type="hidden" name="hiddenData" value="Your Data">
<input id="file-id"type="file" name="file2" ></input>
@endif
</td>
If you want to upload multiple files at once you have to use one form containing all the upload-inputs. 如果要一次上传多个文件,则必须使用一种包含所有上载输入的表单。 Currently your code is producing invalid html because the forms are not closed.
当前,由于未关闭表单,您的代码正在生成无效的html。 But you'll have to find another way to delete files.
但是您必须找到另一种删除文件的方法。 Maybe a checkbox.
也许是一个复选框。
To get the title for each file you have to send it with the form as a hidden input. 要获取每个文件的标题,您必须将其与表单一起发送为隐藏输入。
<form action="{{route('filestest')}}" method="post" enctype="multipart/form-data">
{{csrf_field()}}
<table>
<tr>
<td>Course Report</td>
<td>
@foreach ($temp1 as $fi)
@if($fi->title =="Course Report")
<label><input type="checkbox" name="delete_file" value="{{$fi->id}}" /> delete</label>
@endif
@endforeach
@if($fi->title !="Course Report")
<input id="file-id" type="file" name="file1" />
<input type="hidden" name="file1_title" value="Course Report" />
@endif
</td>
</tr>
</table>
<button type="submit">send file</button>
</form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.