Codeigniter表单验证-单独显示错误问题


Codeigniter Form Validation - Showing Errors Individually problems

我的表单在表中,我试图在输入空间旁边编写表单验证的错误消息。(我把它放在第三列)

的问题是form_error()函数使更多的行高之间的表。我该怎么办?因为如果我使用CSS,它会使"在错误信息发生之前的行高"错误。我需要写之前-之后按钮提交情况的if-else吗?

<table>
        <tr>
            <td>Username : </td>
            <td><input type="text" name="username" value="<?php echo set_value('username'); ?>"/></td>
            <?php
            if($this->input->post("btn") == null)
            {
                echo "<td><span style='font-size: 10px;color:red'>ขั้นต่ำ 6 ตัวอักษร</span></td>";
            }
            else
            {
                echo "<td><span style='font-size:10px;color:red;'>" . form_error('username') ."</span></td>";
            }
            ?>
        </tr> 
        <tr>
            <td>Password : </td>
            <td><input type="password" name="pass" value=""/></td>
            <?php
            if($this->input->post("btn") == null)
            {
                echo "<td><span style='font-size: 10px;color:red'>ขั้นต่ำ 6 ตัวอักษร</span></td>";
            }
            else
            {
                echo "<td><span style='font-size:10px;color:red;'>" . form_error('pass') ."</span></td>";
            }
            ?>
        </tr>
        <tr>
            <td>ยืนยัน Password : </td>
            <td><input type="password" name="pass_confirm" value=""/></td>
            <td><span style="font-size:10px;color:red;"><?php echo form_error('pass_confirm');?></span></td>
        </tr>
        <tr>
            <td>Email : </td>
            <td><input type="text" name="email" value="<?php echo set_value('email'); ?>"/></td>
            <td><span style="font-size:10px;color:red;"><?php echo form_error('email');?></span></td>
        </tr>
        <tr>
        <td colspan="2"><span style="font-size: 10px;color:red;">กรุณากรอกเบอร์มือถือ เพื่อรับ Code ยืนยันการสมัคร (ตัวอย่างเบอร์มือถือ 08xxxxxxxx)</span></td>
        </tr>
        <tr>
            <td>เบอร์มือถือ : </td>
            <td><input type="text" name="phone" value="<?php echo set_value('phone'); ?>"/></td>
            <td><span style="font-size:10px;color:red;"><?php echo form_error('phone');?></span></td>
        </tr>
        <tr>
            <td>กรอกรหัสภาพ :</td>
            <td>    
                <?php echo $captcha['image']; ?>
                <br>
                <input type="text" autocomplete="off" name="userCaptcha" placeholder="Enter above text" value="<?php if(!empty($userCaptcha)){ echo $userCaptcha;} ?>" />
                <?php echo form_error('userCaptcha','<p style="font-size:10px;color:red">','</p>'); ?>
            </td>
        </tr>
    </table>

你可以在一个地方为所有的错误加载错误分隔符,在相关的控制器函数中,不需要单独定义它们,

你可以控制错误信息的高度和样式

$this->form_validation->set_error_delimiters('<span style="font-size: 10px;color:red">', '</span>');

不需要在form-error中使用if-else,所以使用

 <tr>
     <td>Username : </td>
     <td><input type="text" name="username" value="<?php echo set_value('username'); ?>"/>
        <?php
           // if there is validation error, it shows here
          echo form_error('username');
        ?>
   </td>
  </tr>