开发者

mark the input box red if the required field of a form is not filled

i'm using Codeigniter. i have a form which takes information about users. What i want to do is to check whether all the required fields are filled up or not.If any of the required fields is not filled up i want mark that input box red. Right now my codes only check if the required fields are filled up or not. if not it says the "field is required" but how to mark input box.I'm a bit confused how to do this thing.Can somebody help me out with a little hint. Thanks.

the view for my form:

                    <?php     

              $attributes = array('class' => '', 'id' => '');
            echo form_open('register', $attributes); ?>

                <p>
        <label for="name">Name <span class="required">*</span></label>
        <?php echo form_error('name'); ?>
        <br /><input id="name" type="text" name="name"       value="<?php   
                      echo   set_value('name'); ?>"  
</p>

              <p>
        <label for="username">Username <span class="required">*</span></label>
        <?php echo form_error('username'); ?>
        <br /><input开发者_如何学编程 id="username" type="text" name="username"  value="<?php echo set_value('username'); ?>"  
</p>

                 <p>
        <label for="password">Password <span class="required">*</span></label>
        <?php echo form_error('password'); ?>
        <br /><input id="password" type="password" name="password"  value="<?php echo set_value('password'); ?>"  
</p>

                    <p>
          <label for="email">Email <span class="required">*</span></label>
        <?php echo form_error('email'); ?>
        <br /><input id="email" type="text" name="email"                                                           value="<?php                                     echo                                    set_value('email'); ?>"  
</p>

                <p>
        <label for="phone">Phone</label>
        <?php echo form_error('phone'); ?>
        <br /><input id="phone" type="text" name="phone"  value="<?php echo                 set_value('phone'); ?>"  
</p>


            </p>  

              <p>
                   <input type="submit" value="Submit information"  class="formbutton"/>
                          </p>

                <?php echo form_close(); ?>


Generally, I'd recommend creating an textInputError class where you adjust the input style, and then apply it based on the existence of the error...

class="<?php echo (form_error('username') ? 'textInputError' : '') ?>"

in place in the input element...

<input id="username" type="text" name="username"  value="<?php echo set_value('username'); ?>"  class="<?php echo (form_error('username') ? 'textInputError' : '') ?>">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜