tags:

views:

19

answers:

3

I'm running a query via php on a mysql database. With my result set I'm am iterating the following table:

        $resultString = '<table>';
        $resultString .= '<tr>';
        $resultString .= '<th>Index</th>';
        $resultString .= '<th>Title</th>';
        $resultString .= '<th>File</th>';
        $resultString .= '<th>Template File</th>';
        $resultString .= '<th>Pretty URL</th>';
        $resultString .= '<th>Parent</th>';
        $resultString .= '<th></th>';
        $resultString .= '</tr>';

        while($data = mysql_fetch_assoc($results)){
            $resultString .= '<form class="myForm">' ."\n";

            $resultString .= '<tr>' ."\n";

            $resultString .= '<input type="hidden" name="index" value="' . $data['index'] . '">' ."\n";
            $resultString .= '<input type="hidden" name="title" value="' . $data['title'] . '">' ."\n";
            $resultString .= '<input type="hidden" name="file_name" value="' . $data['file_name'] . '">' ."\n";
            $resultString .= '<input type="hidden" name="template_file" value="' . $data['template_file'] . '">' ."\n";
            $resultString .= '<input type="hidden" name="child_of" value="' . $data['child_of'] . '">' ."\n";
            $resultString .= '<input type="hidden" name="pretty_url" value="' . $data['pretty_url'] . '">' ."\n";

            $resultString .= '<td class="indexTd">' . $data['index'] . '</td>' ."\n";
            $resultString .= '<td>' . $data['title'] . '</td>' ."\n";
            $resultString .= '<td>' . $data['file_name'] . '</td>' ."\n";
            $resultString .= '<td>' . $data['template_file'] . '</td>' ."\n";
            $resultString .= '<td>' . $data['pretty_url'] . '</td>' ."\n";
            $resultString .= '<td>' . $this->get_parent_select_list($data['child_of'],$data['index']) . '</td>' ."\n";
            $resultString .= '<td class="buttonTd"><input type="button" class="deletePageButton" value="X" onclick="submit_form(this,\'deletePage\')"></td>' ."\n";

            $resultString .= '</tr>' ."\n";

            $resultString .= '</form>' ."\n";
        }

        $resultString .= '</table>';

The table comes out great, the only problem is my form isn't working at all... viewing it in FireBug I see this:

alt text

The form is closing itself becore all of my input tags can populate it. I HAVE tried putting the tags inside a "<td>" instead of a "<tr>" to no avail....

thoughts?

A: 

egads! you should never nest html elements like that! forms should go inside a <td> or outside the whole table. and you shouldn't put hidden form elements inside a <tr>! they should go in a <td>.

Patricia
ok, sounds great. But what would the solution be for this particular case? I need each row to be it's own form. Should I be nesting another table inside each td that is surrounded by the form?
Jascha
A: 

When you open a tag within another tag, the tag you open will get closed when it's parent gets closed. So this:

<p><form></p>
<p></form></p>

Will (or should) result in:

<p><form></form></p>
<p></p>

You should open your form above the table and close it at the bottom, thus enclosing the entire table in the form.

Placing non-table tags between tr,td,thead,tbody,toot or th tags is bad practice and not w3c compliant

Johan
Btw: It looks like you could do with your complete form in a single td. You have a lot of hidden fields and a single select box. I'd put everything in the td containing the select box. Good luck!
Johan
Thanks Johan. The real issue was matching up the delete button with the form. I have a jquery selector looking for the parent of the clicked element (in a function called submit_form) and then returning my form values from there. The select element can fire it's own event. Anyway, I stuck my form and all the hidden fields in the same td and we're up and running. Thanks again ;)
Jascha
Great to hear it worked, thanks!
Johan
A: 

You'll need to put the form inside a TD.

I would also recommend using a template to generate the HTML, but that's beyond the scope of this question.

Pies