简体   繁体   中英

Retrieve value from a table

I want to know the content of first td tag in each tr tag. 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. 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. 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>

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM