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

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • duandaodao6951 2015-08-08 16:05

    use the form_error() function in view file

    <?php echo form_error('username'); ?>
        <input type="text" name="username" value="<?php echo set_value('username'); ?>" size="50" />
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题