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条)

报告相同问题?