I am working on this school project and I am having trouble getting my form to LOOK and FUNCTION properly.
Issues/Question(s):
1) Can I even Use this PHP “inside” an HTML document?
(The Demo I am Trying to Follow)
This is my FORM ENTRY (IN AN 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 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 namedindex.htmlthe PHP interpreter will ignore it (by default, you can change this, but it’s not really an common or recommended thing to do).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.If your file is named
index.htmltry renaming itindex.phpand see if your code works.