dongwalun2507 2017-01-30 14:00
浏览 49
已采纳

set_value函数在codeIgniter 3中不起作用

I have to set/display the value in form fields during form_validation in codeIgniter but data is not set/displaying by using set_value function.

Here is my code,

view page -

login_form.php

<?= form_open('admin/login');?>

      <?= form_label('Username','username'); ?>
        <?= form_input(['id'=>"username", 'placeholder'=>"Username", "name"=>"username", 'value'=>set_value('username')]); ?><br>
        <?= form_error('username'); ?>
        <br>
      <?= form_label('Password', 'Password'); ?>
        <?= form_password(["id"=>"password", "placeholder"=>"Password", 
        "name"=>"pass", "value"=>set_value('pass')]); ?>
        <?= form_error('pass') ?>
        <br>
        <?php echo form_submit(['value'=>'Login']); ?>

<?= form_close(); ?>

Controller -

admin.php

public function login(){

            $this->load->library('form_validation');
            $this->form_validation->set_rules('username', 'User Name', 'required|alpha|trim');
            $this->form_validation->set_rules('pass', 'Password', 'required');

                if($this->form_validation->run()):
                    echo "Validation Success";
                    else:

                    $this->load->view('login_form']);

                endif;
        }

Please help and give suggestion regarding this.

  • 写回答

4条回答 默认 最新

  • dongtuwu8548 2017-01-30 15:02
    关注

    If you not autoload Form helper add

    $this->load->helper(array('form', 'url'));
    

    and add validation_errors before your form_open

    <?php echo validation_errors(); ?>
    

    for more datails check Codeigniter Validation Form

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

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?