...

View Full Version : this code is throwing up 50+ validation errors???



LJackson
05-29-2009, 05:17 PM
Hi All,

Ok Usually i am able to sort out these validation errors but this time is from something i dont really know nothing about so im not sure what is correct and whats not :)

here is the code

<?php
if(isset($_GET['title'])){
$searchterm = htmlentities($_GET['title']);
$inputtext = htmlentities($_GET['title']);
}
elseif(isset($_GET['searchbox'])){
$inputtext = htmlentities($_GET['searchbox']);
}
else {
$inputtext = "Search Here...";
}
?>

<div id='header'>

<div id='logo'>
<h1>
<a href="http://www.kernow-connect.com" target="_self">
<img src="images/thelogo.png"
title="Kernow Connect -
Online Shopping &amp; Price Comparision - For the smarter shopper"
alt="Kernow Connect -
Online Shopping &amp; Price Comparision - For the smarter shopper"
border='0' /></a></h1>
</div>

<div class="slogantext">
<h1>Online Shopping And Price Comparison</h1>
</div>

<div class="searchcontainer">
<div class="searchicon">
<img src="images/searchimg.png" alt="search icon" title="search icon" /></div>
<div class="searchbar">


<form action="price_results.php" method="get">
<input name="searchbox"
type="text"
id="searchbox"
value="<?php print $inputtext;?>"
size="35"/>
<label>
<select name="category" id="category">
<option value="Everything">All Items</option>
<?php
$optgroups=array('Entertainment'=>array('DVD','CD','Video Games', 'Blu-Ray', 'Books'),
'Computing'=>array('Desktop','Notebook','Netbook','Prnter','Scanner','Software','Accessories'),
'Electronics'=>array('LCD TVs','Plasma TVs','Full HD TVs','MP3 and D.A.P','Digital Cameras',' Home Cinema Systems','DVD Players'),
'Clothing'=>array('T-Shirts &amp; Shirts','Sweatshirts &amp; Fleeces','Shorts &amp; Trousers','Hats &amp; Caps','Gloves','Underware'),
'Miscellaneous'=>array('Fragrences','DIY &amp; Tools','Garden &amp; Outdoors','Health &amp Beauty','
Household Appliances','Toys &amp; Games'));
foreach($optgroups as $key=>$options){
echo "<optgroup label=\"$key\">";
foreach($options as $option){
if(isset($_GET['category']) && $_GET['category']==$option)
echo "<option value=\"{$option}\" selected=\"selected\">{$option}</option>";
else
echo "<option value=\"{$option}\">{$option}</option>";
}
echo "<optgroup>";
}
?>
</select>
</label>
</div>

<div class="searchSubmit">
<input type="image" src="/images/gobutton.png" alt="Submit" />
</div>
</form>

</div>
</div>
<?php }?>

the form optgroup is causing the problems i also think the </label> is in the wrong place as its not yellow like a form element should be?

here is the validation errors
http://validator.w3.org/check?uri=http%3A%2F%2Fwww.kernow-connect.com%2FPrice%2520Comparison%2Fentertainment.php&charset=(detect+automatically)&doctype=Inline&group=0

any ideas how i can get rid of these?

thank you
Luke

thecaligarmo
05-29-2009, 05:23 PM
A couple of notes to probably fix most of the validation errors:

You're last echo is echoing out '<optgroup>' when it should be echoing out '</optgroup>' (forgot the slash)

Also, label is definitely used incorrectly. Put the opening/closing of the label before the input tags.

That should solve most of the issues.

LJackson
05-29-2009, 05:27 PM
hi mate did i now have 6 errors :)

<form action="price_results.php" method="get">
<label>
<input name="searchbox"
type="text"
id="searchbox"
value="<?php print $inputtext;?>"
size="35"/>

<select name="category" id="category">
<option value="Everything">All Items</option>
<?php
$optgroups=array('Entertainment'=>array('DVD','CD','Video Games', 'Blu-Ray', 'Books'),
'Computing'=>array('Desktop','Notebook','Netbook','Prnter','Scanner','Software','Accessories'),
'Electronics'=>array('LCD TVs','Plasma TVs','Full HD TVs','MP3 and D.A.P','Digital Cameras',' Home Cinema Systems','DVD Players'),
'Clothing'=>array('T-Shirts &amp; Shirts','Sweatshirts &amp; Fleeces','Shorts &amp; Trousers','Hats &amp; Caps','Gloves','Underware'),
'Miscellaneous'=>array('Fragrences','DIY &amp; Tools','Garden &amp; Outdoors','Health &amp Beauty','
Household Appliances','Toys &amp; Games'));
foreach($optgroups as $key=>$options){
echo "<optgroup label=\"$key\">";
foreach($options as $option){
if(isset($_GET['category']) && $_GET['category']==$option)
echo "<option value=\"{$option}\" selected=\"selected\">{$option}</option>";
else
echo "<option value=\"{$option}\">{$option}</option>";
}
echo "</optgroup>";
}
?>
</select>
</label>
</div>

<div class="searchSubmit">
<input type="image" src="/images/gobutton.png" alt="Submit" />
</div>
</form>

</div>
</div>
<?php }?>

LJackson
05-29-2009, 05:32 PM
but only 4 of the errors are related to the code above, the ones about the div and the form close tag :)

cheers

LJackson
05-29-2009, 05:43 PM
ok 4 errors left but ive tried fixing them but if i move the tags around it messes up my form elements, these are inside divs to keep them aligned :) think thats why the validator doesnt like it because i have divs within my form tags?

cheers

thecaligarmo
05-29-2009, 05:58 PM
Can you send another link to the new validator? From what I can remember, having divs within a form should be ok.

LJackson
05-29-2009, 06:00 PM
http://validator.w3.org/check?uri=http%3A%2F%2Fwww.kernow-connect.com%2FPrice%2520Comparison%2Fentertainment.php&charset=(detect+automatically)&doctype=Inline&group=0

VIPStephan
05-29-2009, 06:08 PM
One problem is the label and another problem is the closing div tag after the label’s closing tag:


<form action="price_results.php" method="get">
<label>
<input name="searchbox"
type="text"
id="searchbox"
value="<?php print $inputtext;?>"
size="35"/>

<select name="category" id="category">
<option value="Everything">All Items</option>

</select>
</label>
</div>

<div class="searchSubmit">
<input type="image" src="/images/gobutton.png" alt="Submit" />
</div>
</form>

</div>
</div>

A label may only be associated with one form control by either wrapping it around that element or by using the for attribute in conjunction with an ID at the form control. You have wrongly wrapped your label around several elements. Convert that label to a div element since form controls must be in some kind of block element, they may not be direct children of a form element or within an inline element that is direct child thereof. Then write new labels, one for each form control (input and select), assigning them as I’ve mentioned (you can still hide them with CSS if you like).

Then the closing div tag I’ve mentioned has no opening equivalent. You don’t even need that if you convert the label to div as I’ve suggested:



<form action="price_results.php" method="get">
<div>
<label for="searchbox">Search</label> <input name="searchbox" type="text" id="searchbox" value="<?php print $inputtext;?>" size="35"/>

<label for="category">Category</label> <select name="category" id="category">
<option value="Everything">All Items</option>

</select>
</div>

<div class="searchSubmit">
<input type="image" src="/images/gobutton.png" alt="Submit" />
</div>
</form>

LJackson
05-29-2009, 10:38 PM
hi mate thanks for the code unfortunatly it throws up 4 different errors and adds "labels" to my search bar which i dont want, i suppose that label that was there before shouldnt of been there at all as i never had any label show before :)

here is the code i have now

<div class="searchcontainer">
<div class="searchicon">
<img src="images/searchimg.png" alt="search icon" title="search icon" /></div>
<div class="searchbar">


<form action="price_results.php" method="get">
<div>
<label for="searchbox">Search</label> <input name="searchbox" type="text" id="searchbox" value="<?php print $inputtext;?>" size="35"/>

<label for="category">Category</label> <select name="category" id="category">
<option value="Everything">All Items</option>

<?php
$optgroups=array('Entertainment'=>array('DVD','CD','Video Games', 'Blu-Ray', 'Books'),
'Computing'=>array('Desktop','Notebook','Netbook','Prnter','Scanner','Software','Accessories'),
'Electronics'=>array('LCD TVs','Plasma TVs','Full HD TVs','MP3 and D.A.P','Digital Cameras',' Home Cinema Systems','DVD Players'),
'Clothing'=>array('T-Shirts &amp; Shirts','Sweatshirts &amp; Fleeces','Shorts &amp; Trousers','Hats &amp; Caps','Gloves','Underware'),
'Miscellaneous'=>array('Fragrences','DIY &amp; Tools','Garden &amp; Outdoors','Health &amp; Beauty','
Household Appliances','Toys &amp; Games'));
foreach($optgroups as $key=>$options){
echo "<optgroup label=\"$key\">";
foreach($options as $option){
if(isset($_GET['category']) && $_GET['category']==$option)
echo "<option value=\"{$option}\" selected=\"selected\">{$option}</option>";
else
echo "<option value=\"{$option}\">{$option}</option>";
}
echo "</optgroup>";
}
?>
</select>
</div>

<div class="searchSubmit">
<input type="image" src="/images/gobutton.png" alt="Submit" />
</div>
</form>

</div>
</div>
</div>
<?php }?>


im also going to remove the label tags but leave the div tags there see what happens :)

cheers for your help so far

edit if i move the div in red to the green position above the page becomes valid but the input button shifts to the next line? but if i end the div as it should the buttons goes in the correct place but i get the 4 previous validation errors?

LJackson
05-29-2009, 11:06 PM
ok sorted it :D i think

i moved the

<div class="searchbar">

and replaced your<div> with it and then leave the div as it is above in the red and its working :)

thank you all for your help
really appreciate it
Luke



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum