如何使我的表单记住有关数据验证失败的详细信息,而不是重置表单?

时间:2019-05-08 17:24:26

标签: forms codeigniter validation

我曾经有人帮助我使用codeigniter在现场开发工作预定,但现在我找不到他们了。

如果我的表单有错误,它将重置并且我的客户必须重新填写所有框。如何使我的表单保留数据?

不知道您需要什么信息,如果我错过了任何事情,请告诉我

查看-

        <?php include'inc/header.php' ?>
    <!-- Main Container start -->
    <div class="dashboard-container">

      <div class="container">

      <?php include'inc/nav.php' ?>

      <div class="dashboard-wrapper">
       <!-- Row Start -->
            <div class="row">
              <div class="col-lg-12 col-md-12">
                <div class="widget">
                  <div class="widget-header">
                  <?php
                  $user_id = $this->session->user_id;
                  ?>    
                 <div class="col-md-6">                        
                      <h4>Register For Computer Repair</h4>
                    </div>
                  </div>
                     <?php if($msg = $this->session->flashdata('customer')): ?>
                    <div class="row">
                      <div class="col-md-offset-2 col-md-8 col-lg-8">
                      <div class="alert alert-block alert-success fade in">
                        <button data-dismiss="alert" class="close" type="button">
                          ×
                        </button>
                        <h4>
                          <i class="fa fa-check-circle fa-lg"></i><?php echo $msg ?>
                        </h4>
                      </div>
                    </div>
                  </div>
                   <?php endif; ?>
                   <div class="widget-body">
                    <form class="form-horizontal no-margin" action="<?= base_url("register"); ?>" method="post">
                       <input type="hidden" name="created_at" value="<?php echo date("Y-m-d") ?>">
                        <div class="form-group">
                        <label class="col-sm-2 control-label">Customers Name*</label>
                        <div class="col-sm-4">
                          <input type="text" class="form-control" name="name">
                        </div>
                        <label class="col-sm-2 control-label">Customers Address*</label>
                        <div class="col-sm-4">
                          <input type="text" class="form-control" name="address">
                        </div>  
                      </div>
                       <div class="form-group">
                          <div class="col-sm-offset-2 col-sm-4">  
                         <?php echo form_error('name', '<p class="text-danger">', '</p>'); ?>
                          </div>
                          <div class="col-sm-offset-2 col-sm-4">  
                         <?php echo form_error('address', '<p class="text-danger">', '</p>'); ?>
                          </div>  
                        </div>
                      <div class="form-group">
                        <label class="col-sm-2 control-label">Customers Phone Number*</label>
                        <div class="col-sm-4">
                          <input type="text" class="form-control" name="phone">
                        </div>  
                        <label class="col-sm-2 control-label">Customers Email</label>
                        <div class="col-sm-4">
                          <input type="text" class="form-control" name="email">
                        </div>  
                        </div> 
                       <div class="form-group">
                          <div class="col-sm-offset-2 col-sm-4">  
                         <?php echo form_error('phone', '<p class="text-danger">', '</p>'); ?>
                          </div> 
                        </div>
                      <div class="form-group">
                         <label class="col-sm-2 control-label">System Password</label>
                        <div class="col-sm-4">
                          <input type="text" class="form-control" name="password">
                        </div> 
                         <label class="col-sm-2 control-label">Accessories</label>
                        <div class="col-sm-4">
                          <input type="text" class="form-control" name="accessories">
                        </div>
                       </div> 
                        <div class="form-group">
                         <label class="col-sm-2 control-label">Fault Description*</label>
                        <div class="col-sm-4">
                          <textarea class="form-control" name="fault" rows="5"></textarea>
                        </div> 
                         <label class="col-sm-2 control-label">Additional Notes</label>
                        <div class="col-sm-4">
                          <textarea class="form-control" name="note" rows="5"></textarea>
                        </div>
                       </div>
                       <div class="form-group">
                          <div class="col-sm-offset-2 col-sm-4">  
                         <?php echo form_error('fault', '<p class="text-danger">', '</p>'); ?>
                          </div>
</div>
<div class="">&nbsp;</div>
<div class="">&nbsp;</div>
<center><h3>Terms and Conditions</h3></center>
<center><h4>MUST be accepted in order to go-ahead with your repair</h4></center>
<div align="left">
TERMS IN BULLET POINT HERE
</div>
<center>
<div class="form-group">
<div class="">&nbsp;</div>
<div class="">&nbsp;</div>
<div class=""><input class="form-control" name="terms" type="checkbox" value="I Agree" />
<h4>PLEASE TICK ABOVE TO ACCEPT THE TERMS AND CONTINUE</h4>
</div>
</div>
</center>


<div class="form-group">
                          <div class="col-sm-offset-2 col-sm-4">  
                         <?php echo form_error('terms', '<p class="text-danger">', '</p>'); ?>
                          </div>  
                        </div>


                      <div class="form-group">
<center>
                          <button type="submit" class="btn btn-success">Register</button>
</center>
                        </div>
                      </div>   
                    </form>

                  </div>
                </div>
              </div>
            </div>
            <!-- Row End -->
      </div>
        <footer>
          <p>DCSL</p>
        </footer>

      </div>
    </div>
    <!-- Main Container end -->
<?php include'inc/admin_footer.php' ?>

控制器-

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Register extends CI_Controller {

    public function index()
    {



           $this->form_validation->set_rules('name', 'Customers Name', 'required');
           $this->form_validation->set_rules('address', 'Customers Address', 'required');
           $this->form_validation->set_rules('phone', 'Customers Phone Number', 'required');
           $this->form_validation->set_rules('fault', 'Fault Description', 'required');
           $this->form_validation->set_rules('terms', 'Terms and Conditions', 'required');
         if ($this->form_validation->run()):
          $data = $this->input->post();
          $this->load->model('register_model');

                if($this->register_model->add_customer($data)):
                    //echo'<pre>'; print_r($this->db->insert_id()); die();
                    $job_no = $this->db->insert_id();
                    $this->session->set_flashdata('customer','Your Job Number is = ' ."$job_no");
                    else:
                    $this->session->set_flashdata('customer','Your Job Was Not successfully added');  
                endif;
                return redirect('register');

         else:
                $this->load->view('register');
                endif;
        //echo'<pre>'; print_r($data['password']); die();          
         }




}

0 个答案:

没有答案