2012-08-23 22:22


  • codeigniter
  • validation
  • php
  • html
  • forms

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('intelli/content_intelli', $data);

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

    $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('intelli/content_intelli', $data);

View file

<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 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">

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.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • douleijiang8111 douleijiang8111 9年前

    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

    点赞 评论 复制链接分享
  • dousi4472 dousi4472 9年前

    Or you can give like this

    <input type="text" name="name_area" value="">
    <?php echo form_error('name_area'); ?>

    for the different fields the forn_error value changes as like email_area,phone_area.... it displays errors(validations) corresponding to the fieldname.

    点赞 评论 复制链接分享