dtmooir3395 2012-08-23 22:22 采纳率: 0%
浏览 52
已采纳

无法使用codeigniter表单验证

So I am attempting for my first time to use CI's built in form_validation "tool" to much avail and research I can't seem to grasp it. I have everything in my view setup correctly and my controller seems to be right on... My problem is when I click the "submit" button it links to the new function but doesn't display any error messages regardless of what I put in the "name" , "email" boxes. I'm looking to have it display an error message practically anywhere right now I just need it to run through the validation and display an error message.

Controller file

public function intelli()
{
    $data["messages"] = "";
    $this->load->view('engage_header');
    $this->load->view('engage_nav');
    $this->load->view('intelli/content_intelli', $data);
    $this->load->view('engage_footer');

}
public function intelli_email()
{
    $this->load->helper('form', 'url'));
    $this->load->library('form_validation');

    $this->form_validation->set_rules('name_area', 'Name', 'required|alpha|xss_clean');
    $this->form_validation->set_rules('email_area', 'Email', 'required|valid_email|xss_clean');
    $this->form_validation->set_rules('phone_area', 'Phone', 'is_numeric|xss_clean');

    if ($this->form_validation->run() == FALSE) {
        $data["messages"] = "";
    } else {

        $data["messages"] = "The Email has successfully been sent";
    }

    $this->load->view('engage_header');
    $this->load->view('engage_nav');
    $this->load->view('intelli/content_intelli', $data);
    $this->load->view('engage_footer');
}

View file

<?php 
    $this->load->helper("form");
?>
<div class="request_demo">
    <div id="request_logo"></div>
    <div id="top_paragraph">
    Intelliship & HALO deliver immediate and quantifiable ROI.  Schedule a demo to learn how this transportation management software will positively impact your company&apos;s bottom-line profit.
    </div>
    <div id="entry_box">
    <?php  echo validation_errors();
    echo $messages;
    ?>
    <div id="request_form">
    <?php echo form_open('/index.php/site/intelli_email')?>
            <input id="name_area" type="text" placeholder="NAME" value="" required/><br/>
            <input id="email_area" type="text" placeholder="EMAIL" value="" required/><br/>
            <input id="phone_area" type="text" placeholder="PHONE" value=""><br/>
            <input id="submit_req" type="submit" value="SUBMIT">
        </form> 
    </div>
</div>

I know the code is sloppy right now, but I'm just looking for functionality over beauty. also noted since I am loading the helper('form') inside the controller it is redundant to load it in the view.

  • 写回答

2条回答 默认 最新

  • douleijiang8111 2012-08-23 22:29
    关注

    You have only specified id for your form elements. Give them name as well

    <input id="name_area" name ="name_area" type="text" placeholder="NAME" value="" required/><br/>
    <input id="email_area" name="email_area" type="text" placeholder="EMAIL" value="" required/><br/>
    <input id="phone_area" name="phone_area" type="text" placeholder="PHONE" value=""><br/>
    

    Codeigniter hooks up the rule sets, with elements based on name, not id

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码