【问题标题】:CodeIgniter, Smarty and Form Helper. Wrong Link on SubmitCodeIgniter、Smarty 和表单助手。提交时链接错误
【发布时间】:2013-05-18 13:04:14
【问题描述】:

我在使用 CodeIgniter Form Helper 和 Smarty 时遇到了一些小问题。

我使用了这个 (https://github.com/EllisLab/CodeIgniter/wiki/Form-helper-with-Smarty) 表单助手函数。

现在我在控制器中有 addUser() 函数

    public function addUser(){
        $this->load->helper('form');

        $this->form_validation->set_rules('username', 'Benutzername', 'trim|required|min_length[4]|xss_clean');
        $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
        $this->form_validation->set_rules('password', 'Passwort', 'trim|required|min_length[4]|max_length[32]');
        $this->form_validation->set_rules('con_password', 'Passwort bestätigen', 'trim|required|matches[password]');

        if($this->form_validation->run() == FALSE){
            echo "Error! User can not create";
        }else{
            $this->user_model->add_user();
            echo "Done!";
        }
        $this->smarty->display($this->tpl);
    }

我使用了以下 .TPL

    {form url='pageadmin/addUser'}
<p>
    <label for="username">User Name:</label>
    <input type="text" id="username" name="user_name" />
</p>
<p>
    <label for="email_address">Your Email:</label>
    <input type="text" id="email" name="email_address" />
</p>
<p>
    <label for="password">Password:</label>
    <input type="password" id="password" name="password" />
</p>
<p>
    <label for="con_password">Confirm Password:</label>
    <input type="password" id="con_password" name="con_password" />
</p>
<p>
    <input type="submit" value="Submit" />
</p>
{form}

但是现在,当我尝试这个时。我有两个问题。第一个是,当我调用函数 addUser() 时,始终显示消息“错误!用户无法创建”。第二个问题是,表单提交生成的url是这样的“http://dev.url.de/admin/addUser/dev.url.de/pageadmin/addUser”。

非常感谢你,对不起我的英语不好......

【问题讨论】:

    标签: php codeigniter smarty


    【解决方案1】:

    显然您的表单失败了,但您没有返回为什么它失败了。如下更改您的代码,这将告诉您在哪里查找未通过验证的内容:

    if($this->form_validation->run() == FALSE){
                echo validation_errors();
            }else{
    

    验证错误会告诉您哪些规则是/是问题,然后您可以从那里继续进行故障排除。

    至于 URL,这仅仅是因为相对 URL,我不使用 Smarty,所​​以不确定如何使用 base_url() 但以下“可能”工作

    {form url=base_url().'pageadmin/addUser'}
    

    如果这不起作用,应该这样做:

    {form url='../pageadmin/addUser'}
    

    【讨论】:

    猜你喜欢
    • 2012-07-25
    • 1970-01-01
    • 2012-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多