doubaben7394 2014-10-20 10:06
浏览 43
已采纳

CodeIgniter:验证表单未重置输入

I Hope my question is not wrong(not easy for you). to the point...
I have form with validation (check to database MySQL). like this

controller

$ck['no_ktp'] = $this->input->post('no_ktp');
$cek = $this->app_model->getSelectedData("biodata_karyawan",$ck);
if($cek->num_rows()>0)
{
    $this->session->set_flashdata('flash_messages', 'ERROR : No KTP sudah ada di data karyawan..!!!');
    redirect( base_url() . 'karyawan/tambah/' . $site );                    
}
else
{

this code is work with appear messages 'ERROR : No KTP sudah ada di data karyawan..!!!' but the form input will be reset. so I must input this form again.

Question
How to still appear the messages but the field not reset ?

thanks before for your time

  • 写回答

3条回答 默认 最新

  • duannian4784 2014-10-20 10:16
    关注

    This happens because of the redirect. Basically, it reloads the page. What you can do, is after the form is validated, place the inputed values in session variables. If the form is validated correctly and no errors appear, then unset the session variables, else, redirect and on the view page, by default, in each input, place what you have in the session var. kind of like this:

    echo '<input type="text" name="some_name" value="'.(isset($_SESSION['some_name']) ? $_SESSION['some_name'] : '').'" />

    Hope it helps!
    Keep on coding
    Ares.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog