1

I've got an html5 page with a php form in it and I'm getting a few errors. When initially developing, the form, by itself on a page, validated 100% HTML5 (named index.php). The page I put it into (index.html) also validated 100%. Copying the form's code into my page has caused a few validation errors.. which doesn't make sense to me, as they were both 100% accurate.

I'm not sure whether the page including the form should now be index.php or stay as index.html.

Advice?

Below is the HTML and Validation errors as .HTML and .PHP

HTML:

<body>
  <div id="vig"></div>
  <header>
    <h1>LARA</h1>
  </header>  
  <div id="main" class="corners" role="main">
    <div id="jquery_jplayer_1" class="jp-jplayer"></div>
    <div class="jp-audio">
      <div class="jp-type-playlist">
        <div id="jp_interface_1" class="jp-interface">
          <ul class="jp-controls">
            <li><a href="#" class="jp-previous blue" tabindex="1">previous</a></li>
            <li><a href="#" class="blue jp-play" tabindex="1">play</a></li>
            <li><a href="#" class="blue jp-pause" tabindex="1">pause</a></li>
            <li><a href="#" class="blue jp-stop" tabindex="1">stop</a></li>
            <li><a href="#" class="blue jp-next" tabindex="1">next</a></li>
          </ul>
          <div class="jp-progress corners">
            <div class="jp-seek-bar corners blue">
              <div class="jp-play-bar corners"></div>
            </div>
          </div>
          <div class="time">
            <div class="jp-current-time"></div>
            <p id="name"></p>
            <div class="jp-duration"></div>
          </div>
        </div>
      </div>
    </div>
    <div id="mail"> 
      <form id="signup" action="<?=$_SERVER['PHP_SELF']; ?>" method="get"> 
        <fieldset>
          <input type="email" name="email" id="email" class="corners" placeholder="Enter your email address" />
          <span id="response">
            <? require_once('php/store-address.php'); if($_GET['submit']){ echo storeAddress(); } ?>
          </span>
          <input type="submit" id="submit" class="corners blue" value="Go" />           
        </fieldset> 
      </form> 
    </div>
  </div>  
  <footer>
  </footer>
</body>

as .HTML these errors show up:

Line 67, Column 73: Bad value <?=$_SERVER['PHP_SELF']; ?> for attribute action on element form: Illegal character in query component.
        <form id="signup" action="<?=$_SERVER['PHP_SELF']; ?>" method="get"> 
        Syntax of IRI reference:
        Any URL. For example: /hello, #canvas, or http://example.org/. Characters should be represented in NFC and spaces should be escaped as %20.
 Line 71, Column 7: Saw <?. Probable cause: Attempt to use an XML processing instruction in HTML. (XML processing instructions are not supported in HTML.)
       <? require_once('php/store-address.php'); if($_GET['submit']){ echo storeA…

as .PHP these errors show up:

 Line 74, Column 276: End of file seen and there were open elements.
    …s/c09/h02/mnt/127740/domains/lara.fm/html/index.php</b> on line <b>71</b><br />
✉
 Line 70, Column 23: Unclosed element span.
    <span id="response">
✉
 Line 68, Column 14: Unclosed element fieldset.
    <fieldset>
✉
 Line 67, Column 56: Unclosed element form.
    <form id="signup" action="/index.php" method="get"> 
✉
 Line 66, Column 21: Unclosed element div.
    <div id="mail"> 
✉
 Line 41, Column 47: Unclosed element div.
    <div id="main" class="corners" role="main">
✉
 Line 36, Column 22: Unclosed element div.
    <div id="container">
1
  • Is that envelope icon part of the error? Commented May 27, 2011 at 20:58

4 Answers 4

3

Your document is a combination of both HTML and PHP. The source code itself can never validate as HTML.

You should be a validating the script output for HTML conformity not the source code itself.

Sign up to request clarification or add additional context in comments.

4 Comments

That's probably what the problem is.
@technopeasant - See this Firefox plugin for in-browser validation: addons.mozilla.org/en-US/firefox/addon/html-validator
@Jared Farrish - Windows only. Other add ons don't seem as reputable. Any Mac recommendations?
@technopeasant - The HTML Tidy add-on is Windows-only? Wow, that's weird.
1

Your .html file is not being parsed, which is why you get the errors on the .html version. Note, typically PHP is not setup to parse .html-ended files (.php, .php3, .php4, .php5, etc... typically are, though, depending on your php.ini).

Note

If you are copying/pasting your source PHP code and not the output of the script (that the browser sees), this is likely your issue (as Jon Cram points out). To do an in-browser validation, checkout:

https://addons.mozilla.org/en-US/firefox/addon/html-validator/

This is often much easier than copying/pasting your code into the w3c validator.

3 Comments

your answer seems the most credible. What should I do to make this page as stable and validated as possible? If you have an idea, let me know and I'll start another question for it. A few thoughts.. Is there a way I can implement the PHP into the HTML page better? Maybe use JavaScript to launch the PHP strings?
I don't see anything wrong with the markup per se. PHP is parsed at the server, so if you have PHP on a page, make sure it's parsed before it's outputted to the browser. Do you have to have a .html file ending? If not, just use a .php file ending. Otherwise, you could use jQuery/Ajax to get info from the server that's a parsed PHP result.
I see.. well, I'll rename it to index.php and I guess that solves all the problems! Thanks for your help.
0

You'll need to make the file extension .php, and echo out the value of PHP variables. Currently you're doing nothing with the contents of them.

Comments

0

In your .php errors, the first error likely means that your PHP code is generating an error, which is causing your HTML to not validate.

I'm guessing that this part of your PHP code is the culprit:

<? require_once('php/store-address.php'); if($_GET['submit']){ echo storeAddress(); } ?>

There could be a number of problems wrong with this code—the file you required might not exist, storeAddress() might not exist, or $_GET['submit'] isn't working properly. Try using isset($_GET['submit']) or array_key_exists('submit', $_GET) and see if that works.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.