0

The following code will not submit any values.

@foreach ($tests as $test) 
<?php $specialname = $test->test_identity; $myformtestid = str_replace("-", "", $specialname);?>
  <form method="POST" action="/tickets/{{ $test->id }}/edit" name="{{$myformtestid}}" id="{{$myformtestid}}">
  {{ method_field('patch') }}
  {{ csrf_field() }}
    <td style="width: 10%; padding-top: 2px; padding-bottom: 2px; border: 1px solid lightgrey;">
      <select name="accept" class="form control" style="" onclick = "{{$myformtestid}}submitform()">
    @if($test->accept==1)
      <option value="1" selected>Accept</option>
      <option value="0">Reject</option>
      <option value="2">Pending</option>
    @elseif($test->accept==0)
      <option value="1">Accept</option>
      <option value="0" selected>Reject</option>
      <option value="2">Pending</option>
    @else
      <option value="1">Accept</option>
      <option value="0">Reject</option>
      <option value="2" selected>Pending</option>
    @endif
  </select>
  <br>
  Updated: {{\Carbon\Carbon::parse($ticket['updated_at'])->format('d-m-y') }}
  <br>
<?php echo $myformtestid?>

  <script>
    $name = "#<?php echo $myformtestid ?>";
  function {{$myformtestid}}submitform(){
    $.ajax({

      data: $($name).serialize(),
      type: $($name).attr('method'),
      url:  $($name).attr('action'),


    });     
  }

  </script>@endforeach

However, when I changed the $specialname to a string constant, the accept value of the first test_identity was submitted.

What is the issue here?

Update(14 Oct) Instead of Ajax, I used iframe. It is what I needed. For more information, refer to https://stackoverflow.com/a/26380651/11929921

Nova
  • 364
  • 1
  • 15
  • I don't see how the variable `$specialname` is used in your template. If this is a redact version of your code, then you might have removed critical parts in it. Please show the actual code if it is possible. Also please state what php framework / template engine that you're using. – Koala Yeung Oct 14 '19 at 03:46
  • "$specialname = $test->test_identity; " test_identity is the unique id of each test (there is a for loop). I am using it to differentiate between each test. Laravel framework was being used. – Nova Oct 14 '19 at 04:20
  • Is there an error in the console? – suguspnk Dec 09 '19 at 02:56

0 Answers0