简体   繁体   English

html5 php 表单验证问题

[英]html5 php form validation issue

I've got an html5 page with a php form in it and I'm getting a few errors.我有一个 html5 页面,里面有一个 php 表格,我遇到了一些错误。 When initially developing, the form, by itself on a page, validated 100% HTML5 (named index.php).最初开发时,表单本身在页面上验证了 100% HTML5(命名为 index.php)。 The page I put it into (index.html) also validated 100%.我放入的页面(index.html)也验证了 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.将表单的代码复制到我的页面中导致了一些验证错误。这对我来说没有意义,因为它们都是 100% 准确的。

I'm not sure whether the page including the form should now be index.php or stay as index.html.我不确定包含表单的页面现在应该是 index.php 还是保留为 index.html。

Advice?建议?

Below is the HTML and Validation errors as.HTML and.PHP下面是 HTML 和验证错误 as.HTML 和.PHP

HTML: 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: 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 these errors show up: 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">

Your document is a combination of both HTML and PHP.您的文档是 HTML 和 PHP 的组合。 The source code itself can never validate as HTML.源代码本身永远无法验证为 HTML。

You should be a validating the script output for HTML conformity not the source code itself.您应该验证 HTML 一致性的脚本 output 而不是源代码本身。

Your.html file is not being parsed, which is why you get the errors on the.html version.您的.html 文件没有被解析,这就是为什么您在.html 版本上出现错误的原因。 Note, typically PHP is not setup to parse.html-ended files (.php, .php3, .php4, .php5, etc... typically are, though, depending on your php.ini).请注意,通常 PHP 未设置为 parse.html 结尾的文件(.php、.php3、.php4、.php5 等...不过,通常取决于您的 ZE1BFD762321E4109CEE4ZAC.0B6E)。

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).如果您要复制/粘贴源代码 PHP 代码而不是脚本的 output(浏览器看到的),这可能是您的问题(正如 Jon Cram 指出的那样)。 To do an in-browser validation, checkout:要进行浏览器内验证,请检查:

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

This is often much easier than copying/pasting your code into the w3c validator.这通常比将代码复制/粘贴到 w3c 验证器中要容易得多。

You'll need to make the file extension.php, and echo out the value of PHP variables.您需要创建文件扩展名.php,并echo显 PHP 变量的值。 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.在您的.php错误中,第一个错误可能意味着您的 PHP 代码正在生成错误,这导致您的 HTML 无法验证。

I'm guessing that this part of your PHP code is the culprit:我猜你的 PHP 代码的这一部分是罪魁祸首:

<? 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.此代码可能存在许多问题——您需要的文件可能不存在, storeAddress()可能不存在,或者$_GET['submit']无法正常工作。 Try using isset($_GET['submit']) or array_key_exists('submit', $_GET) and see if that works.尝试使用isset($_GET['submit'])array_key_exists('submit', $_GET)看看是否有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM