html5 php表单验证问题

时间:2011-05-27 20:54:08

标签: php html validation html5

我有一个带有php表单的html5页面,我收到了一些错误。在最初开发时,表单本身在页面上验证了100%HTML5(名为index.php)。我把它放入的页面(index.html)也验证了100%。将表单的代码复制到我的页面中会导致一些验证错误..这对我来说没有意义,因为它们都是100%准确的。

我不确定包含表单的页面现在应该是index.php还是保留为index.html。

么?

以下是HTML和验证错误.HTML和.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这些错误出现了:

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这些错误出现了:

 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">

4 个答案:

答案 0 :(得分:3)

您的文档是HTML和PHP的组合。源代码本身永远不能验证为HTML。

您应该验证HTML一致性的脚本输出,而不是源代码本身。

答案 1 :(得分:1)

您的.html文件未被解析,这就是您在.html版本上获得错误的原因。注意,通常PHP不会设置解析.html结束的文件(.php,.php3,.php4,.php5等等......通常,这取决于你的php.ini)。

注意

如果您正在复制/粘贴源PHP代码而不是脚本的输出(浏览器看到),这可能是您的问题(正如Jon Cram指出的那样)。要进行浏览器内验证,请结帐:

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

这通常比将代码复制/粘贴到w3c验证器中容易得多。

答案 2 :(得分:0)

您需要使文件扩展名.php和echo超出PHP变量的值。目前你对它们的内容一无所知。

答案 3 :(得分:0)

.php错误中,第一个错误可能意味着您的PHP代码生成了错误,导致您的HTML无法验证。

我猜你的PHP代码的这一部分是罪魁祸首:

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

此代码可能存在许多问题 - 您需要的文件可能不存在,storeAddress()可能不存在,或$_GET['submit']无法正常工作。尝试使用isset($_GET['submit'])array_key_exists('submit', $_GET),看看是否有效。