Php Form Builder - Contact form in 2 minutes

You just want a fully working contact form, have no more time to spend

That's the right place. Let's start.

  1. You need a php server with php 5.3 or newer running.

    For help, go to Install and run a local PHP server

  2. Add phpformbuilder folder at the root of your project.

    For help, go to Include required files on your page to build form

  3. Copy / paste the following php blocks into your page at the indicated locations :

    <!-- paste following code at the very beginning of your file -->
    <?php
    use phpformbuilder\FormExtended;
    
    session_start();
    include_once rtrim($_SERVER['DOCUMENT_ROOT'], DIRECTORY_SEPARATOR) . '/phpformbuilder/Form.php';
    include_once rtrim($_SERVER['DOCUMENT_ROOT'], DIRECTORY_SEPARATOR) . '/phpformbuilder/FormExtended.php';
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
        if (FormExtended::validateContactForm('extended-contact-form') === true) {
            $sent_message = FormExtended::sendContactEmail('[email protected]', 'extended-contact-form');
        }
    }
    $form = new FormExtended('extended-contact-form', 'horizontal', 'novalidate');
    $form->createContactForm();
    ?>
    
    <!-- paste following code just before </head> -->
    <?php $form->printIncludes('css'); ?>
    
    <!-- paste following code between <body></body> where your form will be displayed -->
    <?php
    if (isset($sent_message)) {
        echo $sent_message;
    }
    $form->render();
    ?>
    <!-- paste following code just before </body> -->
    <?php
        $form->printIncludes('js');
        $form->printJsCode();
    ?>
  4. Replace [email protected] with the email you want the form to be sent

Your form is ready, email will be sent when form is posted and validated.

If your browser throws an error 500, click button below to solve this.

Your browser has thrown this error because php can't find Form.php.

rtrim($_SERVER['DOCUMENT_ROOT'], DIRECTORY_SEPARATOR) should lead to the root of your project.
If works fine if your server is well configured, but it seems that's not the case.

To solve this, open ../phpformbuilder/server.php on your browser and follow the instructions.

More explainations about error 500 are available at https://www.phpformbuilder.pro/documentation/troubleshooting.html#warning-include_once