doudong7256 2012-02-08 14:02
浏览 60
已采纳

使用CodeIgniter form_validation清空POST结果

Can anyone spot why my form always fails the validation? The validation doesn't output any errors, and the POST array is always empty. Suggests to me, its getting submitted to the wrong place but thats not the case.

    <form action="https://www.mydomain.com/account/withdraw" method="post" accept-charset="utf-8">      <fieldset class="six-col">
        <h3>What amount?</h3>
        <span style="font-size:1.3em;position:relative;display:inline;">&pound;</span>
        <input id="amount" type="text" placeholder="1.00" style="font-size:1.3em;width:115px;background-color: transparent;color:white;"/>

    </fieldset>
    <fieldset class="six-col">
        <h3>Charges</h3>
        <span id="charges" style="font-size:1.3em;"></span>
    </fieldset>
    <fieldset class="six-col">
        <h3>You leave with</h3>
        <span id="charges2" style="font-size:1.3em;"></span>
    </fieldset>
    <fieldset class="six-col end-col">
        <input type="submit" id="submit" class="btn" value="Withdraw" style="width:125px;position:absolute;bottom:0" />
    </fieldset>
</form>

Here is the controller

    $this->load->library('form_validation');

    $this->form_validation->set_rules('amount', 'Amount', 'required|xss_clean|trim|numeric|max_length[5]');

    if ($this->form_validation->run() == FALSE)
    {           
        $this->load->helper(array('form', 'url'));
        $data['credit'] = $this->account_m->get_credit();
        $this->load->view('account/withdraw', $data);
    }
    else
    {
        // The withdraw code
    }
    $this->load->view('footer');

Thanks for any help

  • 写回答

1条回答 默认 最新

  • dongye1143 2012-02-08 14:07
    关注

    You don't have name set in the input.. it should be: <input name="amount" id="amount" type="text" placeholder="1.00" style="font-size:1.3em;width:115px;background-color: transparent;color:white;"/>

    Make sure you're actually getting something back.

    If at all possible to test.. echo the post var before the form_validation like so:

    <?php echo $this->input->post('amount'); ?>
    

    If you aren't getting a value back then its the form, try using POST instead of post.

    If you are getting a value back then its the rule. One possibility is the numeric rule, try integer. Try is_natural or try decimal if you're using $0.00.

    Also, use codeigniter's profiler class for development.. http://codeigniter.com/user_guide/general/profiling.html

    <?php $this->output->enable_profiler(TRUE); ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 谁会P4语言啊,我想请教一下
  • ¥20 win11无法启动 持续蓝屏且系统还原失败,无法开启系统保护
  • ¥15 哪个tomcat中startup一直一闪而过 找不出问题
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛