dongmu5246 2015-12-04 18:20
浏览 36

使用模态窗体编辑多个用户(javascript,html)

Hi guys the issue I have is within my users admin page, I have displayed all the admin users within a table each assigned a delete and edit button.

When I click on edit the given users details appear in a modal form. Within the edit details there is a password and confirm password box, when I click on the edit details for the first user, the validation for confirm password appears as "passwords don't match" however when I click on the second user the confirm password does not validate.

Below is the source code I am having issues with any help will be much appreciated:

<a rel="tooltip" title="Edit" id="e<?php echo $id; ?>" href="#edit<?php echo $id; ?>" data-toggle="modal" class="btn btn-success"></i>Edit</a>

<div id="edit<?php echo $id;?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-body">
        <div class="alert alert-info"><strong>Edit User</strong></div>
        <form class="form-horizontal" method="post">
            <div class="control-group">
            <label class="control-label" for="inputEmail">Firstname</label>
            <div class="controls">
                <input type="text" id="inputEmail" name="firstname" value="<?php echo $row['firstname']; ?>" required>
            </div>
            </div>

            <div class="control-group">
            <label class="control-label" for="inputEmail">Lastname</label>
            <div class="controls">
                <input type="text" id="inputEmail" name="lastname" value="<?php echo $row['lastname']; ?>" required>
            </div>
            </div>

            <div class="control-group">
            <label class="control-label" for="inputEmail">Mobile Number</label>
            <div class="controls">
            <input type="text" id="inputEmail" name="mobilenumber" value="<?php echo $row['mobilenumber']; ?>" required>
            </div>
            </div>

            <input type="hidden" id="inputEmail" name="id" value="<?php echo $row['admin_id']; ?>" required>
            <div class="control-group">
            <label class="control-label" for="inputPassword">Password</label>
            <div class="controls">
                <input type="text" name="password" id="password" required>
            </div>
            </div>

            <div class="control-group">
            <label class="control-label" for="inputPassword">Confirm Password</label>
            <div class="controls">
                <input type="text" name="confirmpassword" id="confirmpassword" required>
            </div>
            </div>

            <div class="control-group">
            <div class="controls">
                <button name="edit" type="submit" class="btn btn-success">&nbsp;Update</button>
            </div>
            </div>
        <script type="text/javascript">
            window.onload = function () {
            document.getElementById("password").onchange = validatePassword;
            document.getElementById("confirmpassword").onchange = validatePassword;
            }
            function validatePassword(){
            var confirmpassword=document.getElementById("confirmpassword").value;
            var password=document.getElementById("password").value;
            if(password!=confirmpassword)
            document.getElementById("confirmpassword").setCustomValidity("Passwords Don't Match");
            else
            document.getElementById("confirmpassword").setCustomValidity('');    
            //empty string means no validation error
            }
        </script>
        </form>
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">&nbsp;Close</button>
    </div>
</div>
<?php
    if (isset($_POST['edit'])){

    $admin_id=$_POST['id'];
    $firstname=$_POST['firstname'];
    $lastname=$_POST['lastname'];
    $mobilenumber=$_POST['mobilenumber'];
    $password= sha1 ($_POST['password']);

    mysql_query("update admin set firstname = '$firstname', lastname = '$lastname', mobilenumber = '$mobilenumber', password = '$password' where admin_id='$admin_id'")or die(mysql_error()); ?>
    <script>
    window.location="adminusers.php";
    </script>
    <?php
    }
    }
    ?>

Validation issue

Validation issue 2

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用ESP8266连接阿里云出现问题
    • ¥15 BP神经网络控制倒立摆
    • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
    • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
    • ¥30 Unity接入微信SDK 无法开启摄像头
    • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
    • ¥20 cad图纸,chx-3六轴码垛机器人
    • ¥15 移动摄像头专网需要解vlan
    • ¥20 access多表提取相同字段数据并合并
    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角