$ _POST [' clients']结束时的foreach循环只返回一个值。怎么了?
<?php $clients_to_display = Client::find_all(); ?>
<p><?php foreach ($clients_to_display as $key) {
echo $key->name; ?>:<input type='checkbox' name='clients[]' value=<?php $key->name; ?></><br/>
<?php } ?></p>
if(isset($_POST['submit'])){
$job->name = $_POST["job_name"];
$job->description = $_POST["job_description"];
$job->type = $_POST["job_type"];
$job->age = $_POST["job_age"];
foreach ($_POST['clients'] as $key) {
echo $key;
}
}
答案 0 :(得分:0)
此代码不执行任何操作:
<?php $key->name; ?>
我想你想要:
<?php echo($key->name); ?>
此外,它必须用引号括起来:
value="<?php echo($key->name); ?>"
此外,标记无效。所以,整行应该是:
echo($key->name); ?>:<input type="checkbox" name="clients[]" value="<?php echo($key->name); ?>" /><br/>