PHP code example of jmversteeg / fieldwork

1. Go to this page and download the library: Download jmversteeg/fieldwork library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jmversteeg / fieldwork example snippets


use fieldwork\Form;
use fieldwork\components\TextField;
use fieldwork\components\Button;
use fieldwork\validators\EmailFieldValidator;

// Instantiate a new form
$contactForm = new Form('contactform');

// Add a text field with validation
$emailField = new TextField('email', 'Email address');
$emailField
   ->addValidator(new EmailFieldValidator())
   ->addTo($contactForm);

// Add a submit button
$submitButton = new Button('submit', 'Send', 'submit', Button::TYPE_SUBMIT);
$submitButton
   ->addTo($contactForm);

// Process the form
$contactForm->process();

if($contactForm->isSubmitted())
    echo 'Your email address is ' . $contactForm->v('email');
else
    echo $contactForm->getHTML();