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 三菱伺服电机按启动按钮有使能但不动作
  • ¥20 为什么我写出来的绘图程序是这样的,有没有lao哥改一下
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号