【问题标题】:Codeigniter Form Validation - Showing Errors Individually problemsCodeigniter 表单验证 - 单独显示错误问题
【发布时间】:2016-09-27 04:36:28
【问题描述】:

我的表单在表格中,我尝试在输入空间旁边写下表单验证的错误消息。 (我放在第三栏)

问题在于 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>

【问题讨论】:

    标签: php html css codeigniter


    【解决方案1】:

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

    您可以在那里控制错误消息的高度和样式

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

    【讨论】:

    • 这样您就可以将其标记为正确答案并保持下去!
    猜你喜欢
    • 2014-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-18
    • 1970-01-01
    • 2011-11-05
    • 1970-01-01
    相关资源
    最近更新 更多