Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
610 views
in Technique[技术] by (71.8m points)

php - Form Issue (closing itself early in 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">' ."
";

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

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

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

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

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

        $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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...