VDaemon PHP Library | VDaemon Extension | Table of Contents

VDaemon Tutorial
Including vdaemon.php

On the previous step we created functioning web form. Now we need adding validation to it. But before we will start defining any validation rules we must perform several preparation steps necessary for any pages validated by VDaemon.

All properly written VDaemon pages (both "form" and "action" pages) must begin from include('vdaemon.php'); statement. Of course you must specify right server path to vdaemon.php file. If you placed tutorial pages to your server document root and VDaemon is installed to "<document root>/vdaemon/" folder then path will be "vdaemon/vdaemon.php". This "include" statement must be the first code on your page. No blank lines or spaces allowed before "<?php". This is required because VDaemon uses sessions and redirection headers.

Add <?php include('vdaemon/vdaemon.php'); ?> statement to the beggining of the name.php and the hello.php pages.

VDaemon "form" page also must end with VDEnd(); function call. This function is defined in the vdaemon.php file. Add it to the end of the name.php page.

Now your sourse code must looks like:

name.php source code:

<?php include('vdaemon/vdaemon.php'); ?>
<html>
<head>
<title>Hello!</title>
</head>
<body>
<p>Hello form.</p>
<form method="POST" action="hello.php">
  <table cellpadding="2" cellspacing="0" border="0">
    <tr>
      <td>
        Enter your Name:
      </td>
      <td>
        <input name="Name" type="text" size="25">
      </td>
    <tr>
      <td colspan="2">
        <input type="submit" value="Send">
      </td>
    </tr>
  </table>
</form>
</body>
</html>
<?php VDEnd(); ?>

hello.php source code:

<?php include('vdaemon/vdaemon.php'); ?>
<html>
<head>
<title>Hello!</title>
</head>
<body>
<p>Hello <?php echo $_POST['Name']; ?>!</p>
</body>
</html>

Try to run the name.php page from your browser. After submitting the form you most probably will see this error:
VDaemon Error: Page is accessed using POST method, but validators information isn't defined.

It is because VDaemon "action" pages can accept only VDaemon forms data, but our form is not yet VDaemon form. If in the future you will need to submit several VDaemon and non-VDaemon forms to the same "action" page you can set VDAEMON_POST_SECURITY opion to "false" in the config.php file. This will turn error message off and "action" page will continue executing. But in this case it is possible to take special malicious actions to avoid validation process and VDaemon can't guaranty that validation occured for all form submissions.

Our "action" page is complete now. Further we will not add any changes to the hello.php file in this tutorial.

Continue to Setting Up Form Tag