Yes, but in that case it's better to use readfile().
In this case, I recommend turning the form into a PHP script to handle default values and error message display. For example,
PHP Code:
<?php
// includes scripts that define class TextInput, class TextareaInput &c.
include('FormInputs.php');
// defines class Form
include('Form.php');
$form = new Form();
$form->add(new TextInput('name', 'Name'));
$form->add(new TextInput('email', 'Email Address'));
$form->add(new TextareaInput('comment', 'Comments'));
...
$form->add(new SubmitButton('Submit Comment'));
echo $form;
or:
PHP Code:
<?php
$types = array(
'checkbox' => 'input type="checkbox"',
'hidden' => 'input type="hidden"',
...
'text' => 'input',
'textarea' => 'textarea'
);
$inputs = array(
'name' => array('label' => 'Name', 'value' => ''),
'email' => array('label' => 'Email Address', 'value' => ''),
...
'submit' => array('type' => 'submit', 'value' => 'submit comment')
);
?><form ...>
<?php foreach ($inputs as $name => $info) { ?>
<?php if (isset($info['label'])) { ?>
<label for="<?php echo $name ?>"><?php echo $info['label'] ?>:</label>
<?php } ?>
<<?php if (isset($info['type'])) {echo " type='$info[type]'";} ?> name="<?php echo $name" value="<?php echo isset($_REQUEST[$name]) ? $_REQUEST[$name] : $info['value'] ?>" />
<span id="<?php echo $name, '_err' ?>" class="<?php if (!isset($errors[$name])) {echo 'hidden'} ?>">
<?php if (isset($errors[$name]) { echo $errors[$name] } ?>
</span>
<?php } ?>
</form>
Note that you don't need a hidden form_submitted input. You can simply test whether a certain input from the form is defined:
PHP Code:
if (isset($_POST['comment']) {
...
}
If you really want a special input for the test, use the submit button.