webERP Forum

Full Version: html tags not matching
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.

Isn't this more a shortcoming of the xhtml checking script than a problem with the code?
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 />';
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.
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?