PHP内部的HTML文件 - 简单的表单和验证器

时间:2022-10-17 11:39:32

I am working on this school project and I am having trouble getting my form to LOOK and FUNCTION properly.

我正在研究这个学校项目,我无法正确地将表格变为LOOK和FUNCTION。

This is my School Project

这是我的学校项目

Issues/Question(s):
1) Can I even Use this PHP "inside" an HTML document? (The Demo I am Trying to Follow)

问题/问题:1)我是否可以在HTML文档“内部”使用此PHP? (我试图遵循的演示)

This is my FORM ENTRY (IN AN HTML DOC) :

这是我的表格输入(在HTML DOC中):

<div id="formWrap">
        <div id="form">
            <form action="contact.php" method="post" id="comments_form">
        <div class="row">
        <div class="label">Your Name</div>
        <div class="input">
            <input type="text" id="fullname" class="detail" name="fullname" value="<?php echo isset($_POST['fullname'])? $_POST['fullname'] : ''; ?>" />

            <?php if(in_array('fullname', $validation)): ?><span class="error"><?php echo $error_messages['fullname']; ?></span><?php endif; ?>

        </div> <!-- end input class -->
        <div class="context">e.g. John Smith or Jane Doe</div><!-- end context class -->
     </div><!-- end row class -->

     <div class="row">
        <div class="label">Your Email Address</div>
        <div class="input">
            <input type="text" id="email" class="detail" name="email" value="<?php echo isset($_POST['email'])? $_POST['email'] : ''; ?>" />

            <?php if(in_array('email', $validation)): ?><span class="error"><?php echo $error_messages['email']; ?></span><?php endif; ?>

        </div> <!-- end input class -->
        <div class="context">We will not share your email address with anyone.</div><!-- end context class -->
     </div><!-- end row class -->

     <div class="row">
        <div class="label">Tell Us All About It!</div>
        <div class="input">
            <textarea id="comment" name="comment" class="mess">
                <?php echo isset($_POST['comment'])? $_POST['comment'] : ''; ?>
            </textarea>

            <?php if(in_array('comment', $validation)): ?><span class="error"><?php echo $error_messages['comment']; ?></span><?php endif; ?>

        </div> <!-- end input class -->
     </div><!-- end row class -->

     <div class="submit">
        <input type="submit" id="submit" name="submit" value="Send Message" />
        </form>
        <?php else: ?>
            <p>Thank you for your Message!</p>
        <?php endif; ?>

     </div><!-- end submit class -->
     </div><!-- end form -->

        <?php if($form_complete === FALSE): ?>

     </div><!-- end form wrap -->

3 个解决方案

#1


2  

PHP blocks (<?php ?>) must be processed by the PHP parser/interpreter. This means that the engine needs to know which files to read and which ones to ignore. If this file is named index.html the PHP interpreter will ignore it (by default, you can change this, but it's not really an common or recommended thing to do).

PHP块(<?php?>)必须由PHP解析器/解释器处理。这意味着引擎需要知道要读取哪些文件以及要忽略哪些文件。如果这个文件名为index.html,那么PHP解释器将忽略它(默认情况下,你可以改变它,但这不是一个常见或推荐的事情)。

You can correctly put HTML inside of a PHP file (but outside of the <?php ?> blocks) but you cannot successfully put PHP inside of an HTML file.

您可以正确地将HTML放在PHP文件中(但在<?php?>块之外),但是您无法将PHP成功放入HTML文件中。

If your file is named index.html try renaming it index.php and see if your code works.

如果您的文件名为index.html,请尝试将其重命名为index.php并查看您的代码是否有效。

#2


1  

You can change your server configuration to parse HTML files as PHP if you really want to keep html extension.

如果您真的想保留html扩展名,可以更改服务器配置以将HTML文件解析为PHP。

For example in an Apache server with PHP installed, you can create a .htaccess file in your website directory and use AddType directive:

例如,在安装了PHP的Apache服务器中,您可以在网站目录中创建.htaccess文件并使用AddType指令:

AddType application/x-httpd-php .html

or alternatively you can edit php.ini file.

或者你可以编辑php.ini文件。

#3


0  

You either don't have PHP installed or your web server is not configured to pass .html files to PHP. Judging by the fact that this page exists, PHP is installed, you probably just need to rename your file from index.html to index.php, or reconfigure Apache / your web server.

您要么没有安装PHP,要么您的Web服务器未配置为将.html文件传递给PHP。从这个页面存在的事实来看,安装了PHP,您可能只需要将文件从index.html重命名为index.php,或者重新配置Apache /您的Web服务器。

#1


2  

PHP blocks (<?php ?>) must be processed by the PHP parser/interpreter. This means that the engine needs to know which files to read and which ones to ignore. If this file is named index.html the PHP interpreter will ignore it (by default, you can change this, but it's not really an common or recommended thing to do).

PHP块(<?php?>)必须由PHP解析器/解释器处理。这意味着引擎需要知道要读取哪些文件以及要忽略哪些文件。如果这个文件名为index.html,那么PHP解释器将忽略它(默认情况下,你可以改变它,但这不是一个常见或推荐的事情)。

You can correctly put HTML inside of a PHP file (but outside of the <?php ?> blocks) but you cannot successfully put PHP inside of an HTML file.

您可以正确地将HTML放在PHP文件中(但在<?php?>块之外),但是您无法将PHP成功放入HTML文件中。

If your file is named index.html try renaming it index.php and see if your code works.

如果您的文件名为index.html,请尝试将其重命名为index.php并查看您的代码是否有效。

#2


1  

You can change your server configuration to parse HTML files as PHP if you really want to keep html extension.

如果您真的想保留html扩展名,可以更改服务器配置以将HTML文件解析为PHP。

For example in an Apache server with PHP installed, you can create a .htaccess file in your website directory and use AddType directive:

例如,在安装了PHP的Apache服务器中,您可以在网站目录中创建.htaccess文件并使用AddType指令:

AddType application/x-httpd-php .html

or alternatively you can edit php.ini file.

或者你可以编辑php.ini文件。

#3


0  

You either don't have PHP installed or your web server is not configured to pass .html files to PHP. Judging by the fact that this page exists, PHP is installed, you probably just need to rename your file from index.html to index.php, or reconfigure Apache / your web server.

您要么没有安装PHP,要么您的Web服务器未配置为将.html文件传递给PHP。从这个页面存在的事实来看,安装了PHP,您可能只需要将文件从index.html重命名为index.php,或者重新配置Apache /您的Web服务器。