html5 php form validation issue
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&g开发者_开发问答t;</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">
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.
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.
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.
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.
精彩评论