繁体   English   中英

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

[英]PHP inside HTML file - Simple Form and Validator

我正在这个学校的项目上工作,我无法正确地将表格提交给LOOK和FUNCTION。

这是我的学校项目

问题/问题:
1)我甚至可以在HTML文档“内部”使用此PHP? 我正在尝试的演示

这是我的表单条目(在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 -->

PHP块( <?php ?> )必须由PHP解析器/解释器处理。 这意味着引擎需要知道要读取的文件和要忽略的文件。 如果此文件名为index.html ,PHP解释器将忽略该文件(默认情况下,您可以更改此名称,但这并不是通常或推荐的操作)。

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

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

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

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

AddType application/x-httpd-php .html

或者,您也可以编辑php.ini文件。

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

暂无
暂无

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

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