/simple-php-form

:memo: Easily generate and handle HTML forms in PHP 7.

Primary LanguagePHP

Simple PHP Form

Build Status

Automatic PHP HTML Form generator class. Handles validation, helpers, warnings and more. Supports text fields, text areas, dropdowns, checkboxes, radio buttons and hidden fields.

Validation types supported: required, email, phone, number, lengthmax *, lengthmin *, sizemax *, sizemin *

<?php 
  require('SimplePHPForm.php'); 
  
  $form = new SimplePHPForm();
  $form->Add('text', 'name', '', array('required'), 'Name', '', 'Your name is required.');
  $form->Add('text', 'email', '', array('required', 'email'), 'Email', '', 'Your email is required.');

  if($form->Validate()) // Did the form validate successfully?
  {
    // Success ! Send an email or register user in a database somewhere...
    $form->Reset(); // Reset to default form.
  }
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>SimplePHPForm Basic Example</title>
    <link rel="stylesheet" type="text/css" media="screen" href="css/simplephpform_default.css" />
  </head>
  <body>
    <?php echo $form->Display(); ?>
  </body>
</html> 

Example Scripts

  • Basic usage: ./examples/basic.php
  • Advanced usage: ./examples/advanced.php
  • Center-aligned usage: ./examples/centered.php

Screenshot of Example

Simple PHP Form Example 1

Using Composer

Add to your composer.json file and run php composer update.

{
    "name": "you/your-project",
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/gnat/simple-php-form"
        }
    ],
    "require": {
        "gnat/simple-php-form": "dev-master"
    }
}

Keywords

Forms, User Feedback, Model View Controller, PHP 7 Compatible, PHP 7+, email, input, simple, lean.

License

This project is licensed under the zlib/libpng license.