dtcn30461 2015-08-08 15:51
浏览 43
已采纳

form_validation CodeIgniter

I wonder what did i do wrong so that whatever email address i put in the form, it returns "Unable to access an error message corresponding to your field name Email Address.(email)" and the form cannot be sent successfully.

<?php echo validation_errors('<p class="error">'); ?>

    <?php echo form_open('home/send'); ?>

        <table>
            <tr>
                <th>
                    <label for="name">Name</label>
                </th>
                <td>
                    <input type="text" name="name" id="name" value="<?php echo set_value('name'); ?>">
                </td>
            </tr>
            <tr>
                <th>
                    <label for="email">Email</label>
                </th>
                <td>
                    <input type="text" name="email" id="email" value="<?php echo set_value('email'); ?>">
                </td>
            </tr>
            <tr>
                <th>
                    <label for="message">Message</label>
                </th>
                <td>
                    <textarea name="message" id="message"><?php echo set_value('message'); ?></textarea>
                </td>
            </tr>
        </table>
        <?php echo form_submit('submit', 'Submit'); ?>

    <?php echo form_close(); ?>



function send()
{
    $this->load->library('form_validation');

    $this->form_validation->set_rules('name', 'Name', 'trim|required');
    $this->form_validation->set_rules('email', 'Email Address', 'trim|required|email');
    $this->form_validation->set_rules('message', 'Message', 'trim|required');


    if($this->form_validation->run() == false) {

        $data['page_title'] = "Contact Mike";
        $data['section'] = "contact";

        $this->load->view('templates/header', $data);
        $this->load->view('contact', $data);
        $this->load->view('templates/footer', $data);

    } else {}
  • 写回答

2条回答 默认 最新

  • douwen1929 2015-08-08 16:06
    关注

    Rule should be valid_email, according to documentation:

    $this->form_validation->set_rules('email', 'Email Address', 'trim|required|valid_email'); 
    

    You have placed non-existing 'email' rule there...

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

报告相同问题?

悬赏问题

  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义