Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在提交无效表单后保留到页面(CodeIgniter 3)_Javascript_Php_Jquery_Html_Codeigniter - Fatal编程技术网

Javascript 如何在提交无效表单后保留到页面(CodeIgniter 3)

Javascript 如何在提交无效表单后保留到页面(CodeIgniter 3),javascript,php,jquery,html,codeigniter,Javascript,Php,Jquery,Html,Codeigniter,如果保存我的表单的标记有一个类“hide”,并且只有在单击该页面上的“add”按钮时才能看到,那么在提交无效表单后,如何在该页面上保留 这就是当您单击该页面上的添加按钮时我的URI/URL的外观 其中,#新网关通行证表单是您将看到表单的div 当我尝试刷新该URL时,页面返回默认div并隐藏表单div if ($this->form_validation->run() == true && $this->gatepass_model->addgatepa

如果保存我的表单的
标记有一个类“hide”,并且只有在单击该页面上的“add”按钮时才能看到,那么在提交无效表单后,如何在该页面上保留

这就是当您单击该页面上的添加按钮时我的URI/URL的外观

其中,
#新网关通行证表单
是您将看到表单的div

当我尝试刷新该URL时,页面返回默认div并隐藏表单div

if ($this->form_validation->run() == true && $this->gatepass_model->addgatepass($adddata))
        { 
            //goes to the default view where form div hides
            //TRUE
            $this->load->view("gatepass");
        }
        else {
            //what should I put here?
        }
gatepass.php[控制器]

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Gatepass extends CI_Controller 
{
    public function __construct() {
        parent:: __construct();

        $this->load->helper("url");
        $this->load->helper('form');
        $this->load->model("gatepass_model");
        $this->load->library("form_validation");
    }

    //create a new user
    public function index()
    {
        //$this->load->view('header');
        //$this->load->view('gatepass');

        $this->load->model("gatepass_model");
        $data['records']= $this->gatepass_model->gatepassList();


        $this->load->view('header');
        $this->load->view("gatepass", $data);
    }

     function add_form()
    { //CREATE
        $this->form_validation->set_rules('gatepassNo', 'Gate Pass No', 'required|strip_tags|trim|xss_clean');
        $this->form_validation->set_rules('serviceCardNo', 'Service Card No', 'required|strip_tags|trim|xss_clean');
        $this->form_validation->set_rules('spareParts', 'Spare Parts', 'required|strip_tags|trim|xss_clean');
        $this->form_validation->set_rules('serviceNo', 'Service NO', 'required|strip_tags|trim|xss_clean');
        $this->form_validation->set_rules('accessories', 'Accessories', 'required|strip_tags|trim|xss_clean');
        $this->form_validation->set_rules('dateClaimed', 'Date Claimed', 'callback_dateClaimed_check');


        if ($this->form_validation->run() == true)
        {
            $adddata = array(
                'gatepass_no'       => $this->input->post('gatepassNo'),
                'servicecard_no'    => $this->input->post('serviceCardNo'),
                'item_no'           => $this->input->post('spareParts'),
                'service_no'        => $this->input->post('serviceNo'),
                'accessories'       => $this->input->post('accessories'),
                'date_claimed'      => $this->input->post('dateClaimed'),

                );
        }
        if ($this->form_validation->run() == true && $this->gatepass_model->addgatepass($adddata))
        { 
            //check to see if we are creating the user
            //redirect them to checkout page
            redirect("gatepass");
        }
        else {


        }
    }

我已经看到了你的代码,需要按照下面的方式修改它

  • 在表单中放置一个包含表单哈希值的隐藏字段,然后它将随表单一起提交。获取后,在flashdata中设置错误消息,如

          $this->session->set_flashdata('error',"some field are required"); and  then use redirect on same tab or div by catching that hash value in hidden like bellow.
    
        $hash=$this->input->post("hashfieldname");  //hasfieldname is hidden field in that form
    
  • 然后像这样使用重定向

          $url='/gatpass#'.$hash;
          redirect($url);
    

    在这种情况下,您将能够显示单个消息,因为表单操作不同于实际url,所以需要重定向

    $this->load->view(“网关传递”、$adddata);用户在验证错误后加载页面的相同视图,以及在页面上显示错误时使用的表单_error(“字段_name”),如何在codeigniter中转到该URL?假设我可以在jquery中找到一种方法,在重新加载时删除div的类。但是,如果我只知道$this->load->view(“gatepass”)我无法访问整个URL我怎么能访问该URL呢?我不明白你想要什么?使用redirect()函数发送任何URL。如果不想刷新该页面,请不要在else部分中写入任何内容。不要在else部分中写入任何内容,然后使用form_error(“fieldname”)显示错误。用它,我有点迷路了。我真的很抱歉。我是codeigniter的新手,所以我在这里还是个慢性子。我迷路了。我应该把
    $this->session->set_flashdata('错误',“某些字段是必需的”)放在哪里谢谢!所有这些代码都用于表单验证的else部分,您只需要为hash url的值放置一个隐藏字段,即使是this
    $hash=$this->input->post(“hashfieldname”)
    遇到PHP错误严重性:注意消息:未定义属性:Gatepass::$session Filename:controllers/Gatepass.PHP行号:75
    和此处<代码>致命错误:在第75行的C:\xampp\htdocs\NICI\u CSTESTING\application\controllers\gatepass.php中对非对象调用成员函数set_flashdata()
    使用此链接了解会话并使用$this->load->library('session');在控制器的构造函数中或将其置于config/autoload中,php使会话可通过应用程序使用。
          $this->session->set_flashdata('error',"some field are required"); and  then use redirect on same tab or div by catching that hash value in hidden like bellow.
    
        $hash=$this->input->post("hashfieldname");  //hasfieldname is hidden field in that form
    
          $url='/gatpass#'.$hash;
          redirect($url);