繁体   English   中英

Codeigniter表单验证将无法运行

[英]Codeigniter form validation will not run

似乎可能存在关于表单和表单验证的问题。

我在使表单验证正常工作时遇到了问题。 我创建了一个注册表单,要求用户提供各种信息。 然后,我创建了一个表格,该表格将允许用户编辑他的信息。 表单验证可以完美地在注册表单上运行,但是我无法让它在其他表单上运行验证。

我的观点

<h1>Edit user</h1>

<div id="body">
        <p>Edit user information.</p>

    <?php 



    echo form_open('user_admin/user_update');

    echo validation_errors();

    echo form_hidden('id', $results->id);

    echo "<p><lable>Email:</lable>";
    echo form_input('email', $results->email);
    echo "</p>";


    echo "<p><lable>Name:</lable>";
    echo form_input('name', $results->name);
    echo "</p>";

    echo "<p><lable>Last name:</lable>";
    echo form_input('lastname', $results->lastname);
    echo "</p>";

    echo "<p><lable>Home address:</lable>";
    echo form_textarea('homeaddress', $results->homeaddress);
    echo "</p>";

    echo "<p><lable>Postal address:</lable>";
    echo form_textarea('posteladdress', $results->posteladdress);
    echo "</p>";

    echo "<p><lable>Mobile number:</lable>";
    echo form_input('mobile', $results->mobile);
    echo "</p>";

    echo "<p><lable>Home telephone:</lable>";
    echo form_input('hometel', $results->hometel);
    echo "</p>";

    echo "<p><lable>ID number:</lable>";
    echo form_input('idnum', $results->idnum);
    echo "</p>";

    echo "<p>";
    echo form_submit('edit_submit', 'Update');
    echo "</p>";

    echo form_close();

    ?> 

我的控制器

 public function user_update()
{
    $this->load->library('form_validation');
    $this->load->model('model_users');

    $this->form_validation->set_rules('email', 'Email', 'required|trim|valid_email|is_unique[user.email]');
    $this->form_validation->set_rules('name', 'Name', 'required|trim');
    $this->form_validation->set_rules('lastname', 'Last name', 'required|trim');
    $this->form_validation->set_rules('homeaddress', 'Home address', 'required|trim');
    $this->form_validation->set_rules('posteladdress', 'Postel address', 'required|trim');
    $this->form_validation->set_rules('mobile', 'Mobile number', 'required|trim');
    $this->form_validation->set_rules('hometel', 'Home telphone', 'required|trim');
    $this->form_validation->set_rules('idnum', 'ID Number', 'required');


    $this->form_validation->set_message('is_unique', 'This email address has already been registered. Please try again.');

    if ($this->form_validation->run()==true)
    {

        $id = $this->input->post('id');
        $this->model_users->update_info();
        echo "The users details have been updated successfully";
        redirect ('user_admin/user_main');
    }
    else
    {
        echo "The users details were not updated. Please contact the admistrator!";


    }


}

在控制器处于当前配置的情况下,我可以通过将if语句更改为FALSE来更新数据库。 因此,我现在将帖子信息传递到数据库并进行了更新。

请有人可以看看我的代码,告诉我我做错了什么。

谢谢。

尝试从代码中删除此行,然后重试。

$this->form_validation->set_message('is_unique', 'This email address has already been registered. Please try again.');

我认为这行代码应该进入您自己的验证功能。 如果确实有效,那么只需在codeigniter网站上阅读自定义表单验证功能即可。

如果您使用的是HMVC,则可能会导致验证中的自定义函数出现一些问题,但是解决方法很简单,但是您必须向Google寻求确切的答案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM