2017-04-30 04:38
浏览 51


I am sending an array of checkbox values from a Form to my controller.
I get no value when I try to access them using $_Post. So I decided to try using var_dump(). The result is that I see no value inside my array. If i check 3 checkboxes I get:

array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(0) "" }

I don't understand how to correct this error.

-- My form --

<div class="container">
    <form class="form-horizontal" id="form" action="/MVC/home/languageChosen" method="post">
        <div class="form-group">
                <?php foreach ($data['languageData'] as $languageData): ?>
                        <td><?php echo $languageData['language_name'] ?></td>
                        <td><input type="checkbox" name="learn[]" value="<?php $languageData['language_id'] ?>"></td>
                        <td><input type="checkbox" name="teach[]" value="<?php $languageData['language_id'] ?>"></td>
                <?php endforeach ?>
            <button id="continueButton" name="action" type="submit" class="btn btn-default" value="RegisterLanguage">Continue</button>

-- Controller --

public function languageChosen()
    echo "You posted: " . implode(',', $_POST['learn']); // This results in: You posted: ,,


When I echo $languageData['language_id'], it results in the image below.

enter image description here

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题