Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从html表中获取数据并将其放入php文本字段中?_Php_Javascript_Jquery - Fatal编程技术网

如何从html表中获取数据并将其放入php文本字段中?

如何从html表中获取数据并将其放入php文本字段中?,php,javascript,jquery,Php,Javascript,Jquery,这是我创建的表: <table class="table table-striped table-bordered" id="example"> <thead> <?php foreach ($fields as $field_name => $field_display){ echo "<th>".$field_display."</th>"; }

这是我创建的表:

    <table class="table table-striped table-bordered" id="example">
    <thead>
    <?php
        foreach ($fields as $field_name => $field_display){
             echo "<th>".$field_display."</th>";
        }
    ?>
    </thead>
    <tbody>
    <?php
        foreach ($users as $row){
        echo "<tr>";
        foreach($fields as $field_name => $field_display){
            if($field_name == 'username'){
            echo "<td><a href='#' onclick=\"edituserdata('".$row->username."')\">".$row->$field_name."</a></td>";
        }else{
            echo "<td>".$row->$field_name."</td>";
        }
        }
        echo "</tr>";
        }
    ?>
    </tbody>
    </table>

当我点击一行时,我想让该用户的数据进入引导模式的文本字段。我怎样才能做到这一点?

您可能希望通过ajax完成所有工作,如下所示:

表格html页面

<table class="table table-striped table-bordered" id="example">
    <thead>
    <?php
        foreach ($fields as $field_name => $field_display){
            echo "<th>$field_display</th>";
        }
    ?>
    </thead>
    <tbody>
    <?php
        foreach ($users as $row){
            echo "<tr>";
            foreach($fields as $field_name => $field_display){
                if($field_name == 'username'){
                    echo "<td><a href='#' onclick=\"edituserdata('".$row->username."')\">".$row->$field_name."</a></td>";
                } else {
                    echo "<td>".$row->$field_name."</td>";
                }
            }
            echo "</tr>";
        }
    ?>
    </tbody>
</table>   

<!-- Modal -->
<div id="myModal1" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Update you're data</h3>
    </div>
    <div class="modal-body">

        <!-- NOTE THE EMPTY MODAL -->

    </div>
    <div class="modal-footer">
        <div class="container-fluid">
            <div class="row-fluid">
                <div class="span5" id="message_add_user_id">
                </div>

                <div class="span7">
                    <button id="add_user_submit" type="button" class="btn btn-success">Update <i class="icon-white icon-check"></i> </button>
                    <button class="btn" onClick="document.location.reload(true)" data-dismiss="modal" >Close</button>
                </div>          
            </div>
        </div>
    </div>
</div>
<?php echo form_open('main/update'); ?>

<?php 
    // TODO get username from $_GET['username'] and then retrieve all user information from db
    // TODO echo user data into form fields

    $name = array(
            'name' => 'name',
            'id' => 'name',
            'value' => set_value('name')
    );
    ?>

    <div class="control-group">
        <label class = "control-label" for="name">Name:</label>
        <div>
            <input type="text" name="name" placeholder="Name" id="name" value="">
            <?php echo form_error('name', '<span class="alert-error help-inline">', '</span>')?>
        </div>
    </div>

    <div class="control-group">
        <label class = "control-label" for="name">Username:</label>
        <div>
            <input type="text" name="username" placeholder="Username" id="username" value="">
            <?php echo form_error('username', '<span class="alert-error help-inline">', '</span>')?>
        </div>
    </div>

    <div class="control-group">
        <label class = "control-label" for="name">Password: </label>
        <div>
            <input type="password" name="password" placeholder="Password" id="password" value="">
            <?php echo form_error('password', '<span class="alert-error help-inline">', '</span>')?>
        </div>
    </div>

    <div class="control-group">
        <label class = "control-label" for="name">Retype password: </label>
        <div>
            <input type="password" name="password1" placeholder="Retype password" id="password1" value="">
            <?php echo form_error('password1', '<span class="alert-error help-inline">', '</span>')?>
        </div>
    </div>

    <div class="control-group">
        <label class = "control-label" for="name">Email address: </label>
        <div>
            <input type="email" name="email" placeholder="Email" id="email" value="">
            <?php echo form_error('email', '<span class="alert-error help-inline">', '</span>')?>
        </div>
    </div>

    <div class="control-group">
        <label class = "control-label" for="name">Phone number: </label>
        <div>
            <input type="tel" name="tel" placeholder="Phone number" id="phone_number" value="">
            <?php echo form_error('tel', '<span class="alert-error help-inline">', '</span>')?>
        </div>
    </div>

    <div class="control-group">
        <label class = "control-label" for="name">Description: </label>
        <div>
            <input type="text" placeholder="Description" name="descr" id="description" value="">
            <?php echo form_error('descr', '<span class="alert-error help-inline">', '</span>')?>
        </div>
    </div>

<?php echo form_close();?>
<script>
    function edituserdata(username) {
        $.get('url-to-ajax-page', {username: username}, function(resp) {
            $('#myModal1 .modal-body').html(resp);
            $('#myModal1').modal('show');
        });
    }
</script>

×
更新你的数据
更新
接近
Ajax页面

<table class="table table-striped table-bordered" id="example">
    <thead>
    <?php
        foreach ($fields as $field_name => $field_display){
            echo "<th>$field_display</th>";
        }
    ?>
    </thead>
    <tbody>
    <?php
        foreach ($users as $row){
            echo "<tr>";
            foreach($fields as $field_name => $field_display){
                if($field_name == 'username'){
                    echo "<td><a href='#' onclick=\"edituserdata('".$row->username."')\">".$row->$field_name."</a></td>";
                } else {
                    echo "<td>".$row->$field_name."</td>";
                }
            }
            echo "</tr>";
        }
    ?>
    </tbody>
</table>   

<!-- Modal -->
<div id="myModal1" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Update you're data</h3>
    </div>
    <div class="modal-body">

        <!-- NOTE THE EMPTY MODAL -->

    </div>
    <div class="modal-footer">
        <div class="container-fluid">
            <div class="row-fluid">
                <div class="span5" id="message_add_user_id">
                </div>

                <div class="span7">
                    <button id="add_user_submit" type="button" class="btn btn-success">Update <i class="icon-white icon-check"></i> </button>
                    <button class="btn" onClick="document.location.reload(true)" data-dismiss="modal" >Close</button>
                </div>          
            </div>
        </div>
    </div>
</div>
<?php echo form_open('main/update'); ?>

<?php 
    // TODO get username from $_GET['username'] and then retrieve all user information from db
    // TODO echo user data into form fields

    $name = array(
            'name' => 'name',
            'id' => 'name',
            'value' => set_value('name')
    );
    ?>

    <div class="control-group">
        <label class = "control-label" for="name">Name:</label>
        <div>
            <input type="text" name="name" placeholder="Name" id="name" value="">
            <?php echo form_error('name', '<span class="alert-error help-inline">', '</span>')?>
        </div>
    </div>

    <div class="control-group">
        <label class = "control-label" for="name">Username:</label>
        <div>
            <input type="text" name="username" placeholder="Username" id="username" value="">
            <?php echo form_error('username', '<span class="alert-error help-inline">', '</span>')?>
        </div>
    </div>

    <div class="control-group">
        <label class = "control-label" for="name">Password: </label>
        <div>
            <input type="password" name="password" placeholder="Password" id="password" value="">
            <?php echo form_error('password', '<span class="alert-error help-inline">', '</span>')?>
        </div>
    </div>

    <div class="control-group">
        <label class = "control-label" for="name">Retype password: </label>
        <div>
            <input type="password" name="password1" placeholder="Retype password" id="password1" value="">
            <?php echo form_error('password1', '<span class="alert-error help-inline">', '</span>')?>
        </div>
    </div>

    <div class="control-group">
        <label class = "control-label" for="name">Email address: </label>
        <div>
            <input type="email" name="email" placeholder="Email" id="email" value="">
            <?php echo form_error('email', '<span class="alert-error help-inline">', '</span>')?>
        </div>
    </div>

    <div class="control-group">
        <label class = "control-label" for="name">Phone number: </label>
        <div>
            <input type="tel" name="tel" placeholder="Phone number" id="phone_number" value="">
            <?php echo form_error('tel', '<span class="alert-error help-inline">', '</span>')?>
        </div>
    </div>

    <div class="control-group">
        <label class = "control-label" for="name">Description: </label>
        <div>
            <input type="text" placeholder="Description" name="descr" id="description" value="">
            <?php echo form_error('descr', '<span class="alert-error help-inline">', '</span>')?>
        </div>
    </div>

<?php echo form_close();?>
<script>
    function edituserdata(username) {
        $.get('url-to-ajax-page', {username: username}, function(resp) {
            $('#myModal1 .modal-body').html(resp);
            $('#myModal1').modal('show');
        });
    }
</script>

姓名:

是否要使用jquery执行此操作?如果是,到目前为止您尝试了什么?如果不是,到目前为止您尝试了什么?是的,我想用jquery做这件事,而且我对它还不熟悉,所以我不知道从哪里开始我尝试过像这样设置文本字段的值:value=“”,但这不起作用