Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.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
Php 验证CodeIgniter中的表单后未设置参数_Php_Codeigniter - Fatal编程技术网

Php 验证CodeIgniter中的表单后未设置参数

Php 验证CodeIgniter中的表单后未设置参数,php,codeigniter,Php,Codeigniter,我通过URL传递变量$id,并在表单更新中加载数据,但当我要验证表单时,无法识别值$id function myfunction() { $id = $this->uri->segment(4); echo $id; //yes, print the value $data_user = $this->admin_model->query_data_user($id); $direccion = $data_user[0]-&g

我通过URL传递变量
$id
,并在表单更新中加载数据,但当我要验证表单时,无法识别值
$id

function myfunction() {
    $id = $this->uri->segment(4); 
    echo $id;   //yes, print the value  

    $data_user = $this->admin_model->query_data_user($id);
    $direccion = $data_user[0]->address;
    $phone = $data_user[0]->phone;

    $this->data['address'] = array(
            'name' => 'address',
            'id' => 'address',
            'value' => $address,
            'class' => 'input',
    );

    $this->data['phone'] = array(
            'name' => 'phone',
            'id' => 'phone',
            'value' => $phone,
            'class' => 'input',
    );

    echo $id;  //yes, print the value

    $this->form_validation->set_rules('address', 'Address', 'xss_clean|max_length[100]');
    $this->form_validation->set_rules('phone', 'Phone', 'required|xss_clean|max_length[20]|is_natural_no_zero');

    if ($this->form_validation->run() == true) {
        echo $id;  //here NOT PRINT $id
        $data = array(
                'address' => $this->input->post('address'),
                'phone' => $this->input->post('phone'),
        );

        $id = $this->uri->segment(4); 
        echo $id;  //here not print the value $id

        $this->ion_auth->update_user($id, $data); 
        $this->load->view('includes/template_mensajes', $data);
    }
    $this->load->view('users/update_user', $this->data);
}

$id
在验证我的表单时无法识别,我的错误是什么?

您需要将表单中的$id变量作为隐藏字段传递,并将其作为POST值返回。

您需要将表单中的$id变量作为隐藏字段传递,并将其作为POST值返回。

如果我没有弄错,并且myfunction是控制器中名为。。。比如说“我的控制者”。那么您应该只发送以下url:
http://localhost/mycontroller/myfunction/1234

并将您的操作更新为接受ID参数$ID。CodeIgniter将处理其余部分

function myfunction($id) {
...
}

如果我没有弄错,我的函数是控制器中的一个动作,名为。。。比如说“我的控制者”。那么您应该只发送以下url:
http://localhost/mycontroller/myfunction/1234

并将您的操作更新为接受ID参数$ID。CodeIgniter将处理其余部分

function myfunction($id) {
...
}

您将表格提交到哪里。确实要在表单的action属性的URI中传递ID吗

例如,您的表单打开标记应该如下所示


您将表单提交到哪里。确实要在表单的action属性的URI中传递ID吗

例如,您的表单打开标记应该如下所示


将我的id添加到我的URL末尾后,例如
www.whsconcepts.com/?id=100
, 我把它放在表格里。例如:

form_open('the url I want' . $_Get ['id'])

将我的id添加到我的URL末尾后,例如
www.whsconcepts.com/?id=100
, 我把它放在表格里。例如:

form_open('the url I want' . $_Get ['id'])

我尝试了您的答案:anchor('user/myfunction/'。$user['id'],'update')和我的函数myfunction($id),并生成了以下错误:遇到了一个PHP错误。严重性:警告。消息:缺少user::myfunction()的参数1。Filename:controllers/user.php另一个错误是:遇到php错误。严重性:通知。消息:未定义变量:id.Filename:controllers/user.php。我希望这个选项适合我。感谢您的回答。我可以在($this->form\u validation->run()==true)中传递基于您答案的值,{无法识别值$id;。感谢您的回答。我尝试了您的答案:锚定('user/myfunction/'。$user['id','update')和我的函数myfunction($id)并生成此错误:遇到PHP错误。严重性:警告。消息:缺少user::myfunction()的参数1.Filename:controllers/user.php另一个错误是:遇到了php错误。严重性:注意。消息:未定义变量:id.Filename:controllers/user.php。我希望此选项对我有效。感谢您的回答。但是,我可以在($this->form\u validation->run()==true)中传递答案中的值{无法识别$id;。感谢您的回答。您是否尝试将变量$id设置为全局变量?是否尝试将变量$id设置为全局变量?您好。感谢您的回答。您已经回答了我的问题。我认为这是答案的一部分,也是完成我在回答中解释的内容的唯一方法。但更重要的是,使用$this->uri->segment(4);在他的代码中是错误的,应该使用CI控制器操作的正确方法来完成。嗨,谢谢你的回答。你已经回答了我的问题。我认为这是答案的一部分,也是完成我在回答中解释的内容的唯一方法。但更重要的是使用$this->uri->segment(4);在他的代码中是错误的,应使用CI控制器操作的适当方法执行。