1

我有一个带有重置和创建按钮的“创建用户”表单。此重置按钮不适用于表单中的某些下拉菜单。

此外,重置按钮不会在验证后清除表单中的所有值。它只清除验证后输入的值。

这是我的代码:

<div class="form-action clearfix">
<button type="button" onClick="clearForm()" > Reset </button>
<button class="button" type="button" id="button"       onclick="doAjax('index.php/users/createUser', convertFormJson('#createUserForm'));">Create</button>

function clearForm() {
document.getElementById('createUserForm').reset(); 
}

形式:

<?php echo validation_errors(); ?>
            <div class="container_12 clearfix leading" >
                <div class="grid_12">

                        <!--<form class=    "form has-validation">-->
                        <?php 

                            $attributes = array('class' => 'form has-validation', 'id' => 'createUserForm');
                            echo form_open('/users/createUser', $attributes); 

                        ?>
                        <div class="clearfix">
                            <label for="form-name" class="form-label">First Name <em>*</em></label>
                            <div class="form-input">
                                <input type="text" id="form-name" name="firstname" required="required" placeholder="Enter the first name" value="<?php echo set_value('firstname'); ?>" />
                            </div>
                        </div>

                        <div class="clearfix">
                            <label for="form-name" class="form-label">Last Name <em>*</em></label>
                            <div class="form-input">
                                <input type="text" id="form-name" name="lastname" required="required" placeholder="Enter the last name" value="<?php echo set_value('lastname'); ?>"/>
                            </div>
                        </div>

                        <div class="clearfix">
                            <label for="form-email" class="form-label">Email <em>*</em></label>
                            <div class="form-input"><input type="email" id="form-email" name="email" required="required" placeholder="A valid email address" value="<?php echo set_value('email'); ?>"/></div>
                        </div>

                        <!--
                        <div class="clearfix">
                            <label for="form-birthday" class="form-label">Birthdate</label>
                            <div class="form-input"><input type="date"  id="form-birthday" name="date" placeholder="mm/dd/yyyy" value="<?php //echo set_value('date'); ?>" class="date"/></div>
                        </div>
                        -->

                            <div class="clearfix">
                            <label for="form-username" class="form-label">Username <em>*</em></label>
                            <div class="form-input">
                                <?php echo form_error('username'); ?>
                                <input type="text" id="form-username" name="username" value="<?php echo set_value('username'); ?>" required="required" maxlength="30" placeholder="Alphanumeric (max 30 char.)" />
                            </div>
                        </div>

                        <div class="clearfix">
                            <label for="form-password" class="form-label">Password <em>*</em></label>
                            <div class="form-input">
                                <?php echo form_error('password'); ?>
                                <input type="password" id="form-password" name="password" value="<?php echo set_value('password'); ?>" maxlength="30" placeholder="Min 8 char. containing a capital, number and/or symbol" />
                            </div>
                        </div>

                        <div class="clearfix">
                            <label for="form-password-check" class="form-label">Password check <em>*</em></label>
                            <div class="form-input">
                                <?php echo form_error('passconf'); ?>
                                <input type="password" id="form-password-check" name="passconf" value="<?php echo set_value('passconf'); ?>" data-equals="password" maxlength="30" placeholder="Re-enter your password" />
                            </div>
                        </div>

                        <div class="clearfix">
                            <label for="form-group" class="form-label">Group <em>*</em></label>
                            <div class="form-input">
                                <?php 
                                        $groupsData[' '] = "--";
                                        $groupJs = 'id="form-group"';
                                        echo form_dropdown('groupId', $groupsData,' ',$groupJs);
                                    ?>
                            </div>
                        </div>

                        <div class="clearfix">
                            <label for="form-language" class="form-label" >Language <em>*</em></label>
                            <div class="form-input">
                                <select id="form-language" name="language">
                                    <option value ="" > -- </option>
                                    <option value ="1">English</option>
                                    <option value ="2">French</option>    
                                </select>
                            </div>
                        </div>

                        <div class="clearfix">
                            <label for="form-timezone" class="form-label"  >Timezone <em>*</em></label>
                            <div class="form-input">
                                <?php echo timezone_menu('UM5', 'form-timezone'); ?>
                             </div>
                        </div>

请帮帮我。

4

0 回答 0