2015-02-06 14:04
浏览 101


I have a dynamically formed table with radio buttons to choose pass or fail in each rows. Below are my codes:

<form name="form2" method="post" action="/admin/testresults/update/added">
  <?php if(isset($rows)){ $i=1; $pass=$ fail='' ; foreach ($rows as $row) { (($row->result == 1) ? $pass='checked' : $fail='checked'); print "
    <td>".$row->name." ".$row->last_name."</td>
      <input type='radio' name='".$row->userId."' value='1' ".$pass.">Pass
      <input type='radio' name='".$row->userId."' value='0' ".$fail.">Fail
      <input type='hidden' name='".$row->userId."' value='".$row->userId."' </td>
  "; $i++; } print "
    <td colspan='3'>
      <input class='ember-view btn btn-danger' type='submit' />
  </tr>"; } ?>

I'm using the below codes in my controller:

$inputs = Input::get();
foreach($inputs as $input){

What I want to pass into updateCandidate() is the student id and the selected radio button value (1/0). How can I do this?


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doutang1946
    doutang1946 2015-02-06 14:29

    Firstly, I agree with @Chelius comments, look at laravel's documentation around blade templating and @if / @foreach and the use of {{ Form::input }}.

    However in answer to your question - you will need to name you inputs better to retrieve the user id and the verbose PHP version should end up looking like this:

      <input type='radio' name='results[".$row->userId."]' value='1' ".$pass.">Pass
      <input type='radio' name='results[".$row->userId."]' value='0' ".$fail.">Fail
      <input type='hidden' name='".$row->userId."' value='".$row->userId."'

    When processing, your code should then be:

    $inputs = Input::get();
    foreach($inputs['results'] as $userId => $result){
        TestResults::updateCandidate($userId, $result);

    Note that you may need to update your "updateCandidate" function to accept the user id and the result.

    点赞 评论