开发者

Form Issue (closing itself early in table)

开发者 https://www.devze.com 2023-01-15 10:31 出处:网络
I\'m running a query via php on a mysql database.With my result set I\'m am iterating the following table:

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:

Form Issue (closing itself early in table)

The form is closing itself becore all of my input tags can populate it. I HAVE tried putting the tags inside a "<td>" ins开发者_如何转开发tead of a "<tr>" to no avail....

thoughts?


When you open a tag within another tag, the tag you open will get closed when its 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,tfoot or th tags is bad practice and not w3c compliant


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消