Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts

    Post this code is throwing up 50+ validation errors???

    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 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=ht...Inline&group=0

    any ideas how i can get rid of these?

    thank you
    Luke

  • #2
    New Coder
    Join Date
    Dec 2008
    Posts
    58
    Thanks
    2
    Thanked 1 Time in 1 Post
    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.

  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts
    hi mate did i now have 6 errors
    PHP Code:
        <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 }?>
    Last edited by LJackson; 05-29-2009 at 05:30 PM.

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts
    but only 4 of the errors are related to the code above, the ones about the div and the form close tag

    cheers

  • #5
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts
    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

  • #6
    New Coder
    Join Date
    Dec 2008
    Posts
    58
    Thanks
    2
    Thanked 1 Time in 1 Post
    Can you send another link to the new validator? From what I can remember, having divs within a form should be ok.

  • #7
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts

  • #8
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,637
    Thanks
    6
    Thanked 1,004 Times in 977 Posts
    One problem is the label and another problem is the closing div tag after the label’s closing tag:

    Code:
        <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:

    Code:
        <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>
    Last edited by VIPStephan; 05-29-2009 at 06:11 PM.

  • #9
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts
    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
    PHP Code:
        <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>
    [COLOR="Red"]</div>[/COLOR]

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

    [COLOR="Green"]</div>[/COLOR]
    </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?
    Last edited by LJackson; 05-29-2009 at 10:56 PM.

  • #10
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts
    ok sorted it i think

    i moved the
    PHP Code:
    <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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •