【问题标题】:form_validation CodeIgniterform_validation CodeIgniter
【发布时间】:2015-08-08 15:51:18
【问题描述】:

我想知道我做错了什么,所以无论我在表单中输入什么电子邮件地址,它都会返回“无法访问与您的字段名称电子邮件地址相对应的错误消息。(电子邮件)”并且表单无法成功发送。

<?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 {}

【问题讨论】:

  • 澄清你的问题

标签: php codeigniter


【解决方案1】:

根据文档,规则应该是 valid_email

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

您在那里放置了不存在的“电子邮件”规则...

【讨论】:

    【解决方案2】:

    在视图文件中使用form_error()函数

    <?php echo form_error('username'); ?>
        <input type="text" name="username" value="<?php echo set_value('username'); ?>" size="50" />
    

    【讨论】:

      猜你喜欢
      • 2015-08-07
      • 1970-01-01
      • 2018-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多