在记录更新表单中返回验证消息时出错



我在检查更新特定记录信息的表单的验证功能时遇到问题,显然验证有效,但它们返回了一个错误,我只需要打印它,这样你就可以更好地了解发生了什么:

此处为错误图像

显然,验证是有效的,但页面地址不是表单的,这就是为什么页面是完全空的,只包含验证消息。

form_update.php


<?php if (!empty($errors)): ?>
<div class="alert alert-danger">
<?php foreach ($errors as $error): ?>
<li><?= $error ?></li>
<?php endforeach; ?>
</div>
<?php endif; ?>
<form action="<?= site_url('update/'.$hxh['id_hunter'])?>" method="POST">
<div class="form_group">
<div class="form_group">
<div for="name_hunter">Nome:
<input type="text" class="form-control" name="name_hunter" maxlength="30" value="<?= $hxh['aome_hunter'] ?>">
</div>
</div>
<br>
<div class="form_group">
<div for="age_hunter">Idade:
<input type="text" class="form-control" name="age_hunter" onkeypress="$(this).mask('00', {reverse: true});" value="<?= $hxh['age_hunter'] ?>">
</div>
</div>
<br>
...
<button type="submit" class="btn btn-primary"><i class="fa fa-arrows-rotate"></i>&nbsp;Update</button>
</form>
  • HunterController.php

public function formUpdateHunter($id_hunter)
{
try {
$hunter = new HunterModel();
$dados['hxh'] = $hunter->where('id_hunter', $id_hunter)->first();
return view('form_update', $dados);
} catch (Exception $e) {
exit($e->getMessage());
}
}
public function updateHunter()
{
try {
helper(['form','url','html']);
$hunter = new HunterModel();
$id_hunter = $this->request->getPost('id_hunter');
$dados = [
'name_hunter' => $this->request->getPost('name_hunter'),
'age_hunter' => $this->request->getPost('age_hunter'),
'height_hunter' => $this->request->getPost('height_hunter'),
'weight_hunter' => $this->request->getPost('weight_hunter'),
'type_hunter' => $this->request->getPost('type_hunter'),
'type_nen' => $this->request->getPost('type_nen'),
'type_blood' => $this->request->getPost('type_blood')
];
if ($hunter->update($id_hunter, $dados)){
return $this->response->redirect(site_url('listing'));       
} else {
return view('form_update', ['errors' => $hunter->errors()]);
}
} catch (Exception $e) {
exit($e->getMessage());
}
}

我怀疑它停止渲染html,因为在updateHunter中,模板缺少表单action属性的$hxh['id_hunter']变量。

尝试在updateHunter中将猎人数据再次传递到模板(我只更改了else(:

public function updateHunter()
{
try {
helper(['form','url','html']);
$hunter = new HunterModel();
$id_hunter = $this->request->getPost('id_hunter');
$dados = [
'name_hunter' => $this->request->getPost('name_hunter'),
'age_hunter' => $this->request->getPost('age_hunter'),
'height_hunter' => $this->request->getPost('height_hunter'),
'weight_hunter' => $this->request->getPost('weight_hunter'),
'type_hunter' => $this->request->getPost('type_hunter'),
'type_nen' => $this->request->getPost('type_nen'),
'type_blood' => $this->request->getPost('type_blood')
];
if ($hunter->update($id_hunter, $dados)){
return $this->response->redirect(site_url('listing'));       
} else {
$dados['id_hunter'] = $id_hunter;
return view('form_update', ['errors' => $hunter->errors(), 'hxh' => $dados]);
}
} catch (Exception $e) {
exit($e->getMessage());
}
}

相关内容

  • 没有找到相关文章

最新更新