Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
html tags not matching
01-20-2012, 11:36 AM,
#1
html tags not matching
Tim,

I started using the check_closing_tags script. So far most of the problems it reports are due to code, written in this fashion:
if (condition) {
echo '<table class="table1">';
some code;
}
else {
echo '<table class="table1">';
some other code;
}
echo '</table>;

The script reports that there are two opening tags and only one closing tag.
I see two ways to fix it:
1. Separate html and php, so there is no html inside the if-else statements.
2. Put complete html statement in each side of if-else, so there is always a pair of opening and closing tags.
We should select one way to do it and keep it throughout the code.

Reply
01-20-2012, 03:11 PM, (This post was last modified: 01-20-2012, 05:49 PM by phil.)
#2
RE: html tags not matching
Isn't this more a shortcoming of the xhtml checking script than a problem with the code?
Phil Daintree
webERP Admin
Logic Works Ltd
http://www.logicworks.co.nz
Reply
01-21-2012, 06:02 AM,
#3
RE: html tags not matching
Tim,
I will work with check_html script first. Then I am planning to install W3C Validator on my server to verify the result.
Phil,
It is both. The problem of the script that it does not know how to evaluate if-else correctly. The problem with the code is that it is confusing and prone to errors. You can easily miss that some set of conditions do not create some tags at all. Here to illustrate my point some code from AccountSections.php. What happens when DB_num_rows($result) == 0 ?

if (isset($_GET['SelectedSectionID'])) {
//editing an existing section

$sql = "SELECT sectionid,
sectionname
FROM accountsection
WHERE sectionid='" . $_GET['SelectedSectionID'] ."'";

$result = DB_query($sql, $db);
if ( DB_num_rows($result) == 0 ) {
prnMsg( _('Could not retrieve the requested section please try again.'),'warn');
unset($_GET['SelectedSectionID']);
} else {
$myrow = DB_fetch_array($result);

$_POST['SectionID'] = $myrow['sectionid'];
$_POST['SectionName'] = $myrow['sectionname'];

echo '<input type=hidden name="SelectedSectionID" value="' . $_POST['SectionID'] . '" />';
echo '<table class="selection">
<tr>
<td>' . _('Section Number') . ':' . '</td>
<td>' . $_POST['SectionID'] . '</td>
</tr>';
}

} else {

if (!isset($_POST['SelectedSectionID'])){
$_POST['SelectedSectionID']='';
}
if (!isset($_POST['SectionID'])){
$_POST['SectionID']='';
}
if (!isset($_POST['SectionName'])) {
$_POST['SectionName']='';
}
echo '<table class="selection">
<tr>
<td>' . _('Section Number') . ':' . '</td>
<td><input tabindex="1" ' . (in_array('SectionID',$Errors) ? 'class="inputerror"' : '' ) .' type="text" name="SectionID" class="number" size="4" maxlength="4" value="' . $_POST['SectionID'] . '" /></td>
</tr>';
}
echo '<tr><td>' . _('Section Description') . ':' . '</td>
<td><input tabindex="2" ' . (in_array('SectionName',$Errors) ? 'class="inputerror"' : '' ) .' type="text" name="SectionName" size="30" maxlength="30" value="' . $_POST['SectionName'] . '" /></td>
</tr>';

echo '<tr><td colspan="2"><div class="centre"><input tabindex="3" type="submit" name="submit" value="' . _('Enter Information') . '" /></div></td></tr>';
echo '</table><br />';
Reply
01-21-2012, 08:07 AM,
#4
RE: html tags not matching
OK, I correct first the things that the script finds, but in the future we need a more thorough testing tool. The validator returns about 2-3 times more errors than the script.
Reply
01-26-2012, 09:07 AM,
#5
RE: html tags not matching
Tim,
I fixed all problems that check_html script is reporting. Some errors that it still shows are false positives, because it does not know how to analyze multi line tags.
What are our next steps?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)