Muhammad Raheel
Muhammad Raheel

Reputation: 19882

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.

enter image description here

And here is the first row result

enter image description here

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.

Upvotes: 2

Views: 2354

Answers (2)

Pankaj Kumar
Pankaj Kumar

Reputation: 21

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. 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>

Upvotes: 1

Muhammad Raheel
Muhammad Raheel

Reputation: 19882

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.

Upvotes: 3

Related Questions