简体   繁体   English

第一个表单未显示在循环中,而其他表单显示

[英]First Form not displayed being in loop while others display

I am working on an existing application.我正在处理现有的应用程序。 I am encountering a strang issue.我遇到了一个奇怪的问题。 Here is my loop.这是我的循环。

<tbody>
<?php if($results->num_rows > 0 ): ?>
    <?php foreach ($results->result() as $row1): ?>            
        <tr>
            <td class="td_data"><a href="<?php echo site_url('campaign/search/customer_name/'.$row1->customer_name)?>"><?php echo $row1->customer_name; ?></a></td>
            <td class="td_data"><?php echo $row1->postcode; ?>&nbsp;</td>
            <td class="td_data"><a href="<?php echo site_url('campaign/search/company/'.$row1->company);?>"><?php echo $row1->company; ?></a></td>
            <td class="td_data"><?php echo $row1->enquiry_status; ?></td>                
            <td class="td_data"><?php echo $row1->form_source; ?></td>
            <td class="td_data"><?php echo anchor('customer/edit/' . $row1->customer_id, 'Edit'); ?></td>
            <td class="td_data">
                <a href="javascript:;" id="member_login_link<?php echo $row1->customer_id?>">Login</a>
                <?php $action   =   $this->config->item('front_site_url').'members/login';?>
                <form id="member_login<?php echo $row1->customer_id?>" action="<?php echo $action;?>" method="post" >
                    <input type="hidden" name="username" value="<?php echo $row1->username?>"/>
                    <input type="hidden" name="password" value="<?php echo $row1->password?>"/>
                    <input type="hidden" name="submitted" value="yes" />
                </form>
                <script type="text/javascript">
                    $('#member_login_link<?php echo $row1->customer_id?>').click(function(){
                        $('#member_login<?php echo $row1->customer_id?>').submit();
                    });
                </script>
            </td>
        </tr>
    <?php endforeach; ?>
<?php else: ?>
     <tr>
        <td class="td_data">No Record Found</td>
    </tr>
<?php endif; ?>
</tbody>

This creates a list.这将创建一个列表。 And inspecting element displays this.并检查元素显示这一点。

Here is the result of firebug which is fine on all the elements except the first.这是 firebug 的结果,它对除第一个之外的所有元素都很好。

在此处输入图片说明

And here is the first row result这是第一行结果

在此处输入图片说明

I am unable to understand why this is happening.我无法理解为什么会发生这种情况。 I have checked on different browsers and all have same issue.我检查了不同的浏览器,都遇到了同样的问题。

EDITS:编辑:

This list that is being generate has form in each row.正在生成的这个列表在每一行中都有形式。 clicking on Login opens a tabs and asks for username and password.单击登录会打开一个选项卡并要求输入用户名和密码。 But the first row does not have form tags so it is not opening tag.但是第一行没有表单标签,所以它不是开始标签。

I have found the issue.我发现了这个问题。 A form closing tag was not written in header for Search functionality.未在标题中写入用于搜索功能的表单结束标记。 so it was picking the first form closing tag and the form opening tag in the list was left to be hanged so it was not working.所以它选择了第一个表单结束标签,而列表中的表单开始标签被挂起,所以它不起作用。

Use empty form tag before main form tag inside foreach loop, then first empty form tag will be removed by foreach loop and functionality will work fine.在 foreach 循环内的主表单标签之前使用空表单标签,然后 foreach 循环将删除第一个空表单标签,功能将正常工作。 For example:例如:

<div>
    <form></form>
    <form id="member_login<?php echo $row1->customer_id?>" action="<?php echo $action;?>" method="post" >
        <input type="hidden" name="username" value="<?php echo $row1->username?>"/>
        <input type="hidden" name="password" value="<?php echo $row1->password?>"/>
        <input type="hidden" name="submitted" value="yes" />
    </form>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM