Skip to content

Latest commit

 

History

History
54 lines (40 loc) · 1.66 KB

README.md

File metadata and controls

54 lines (40 loc) · 1.66 KB

📝 Simple PHP Form

workflow

Automatic HTML <form> with validation, messages, warnings and more!

  • Form fields: text, textarea, dropdown, checkbox, radio and hidden
  • Validators: required, email, phone, number, lengthmax *, lengthmin *, sizemax *, sizemin *
<?php 
  require('SimplePHPForm.php'); 
  
  $form = new SimplePHPForm();
  $form->add('name', 'text', '', ['required'], 'Name', '', 'Your name is required.');
  $form->add('email', 'text', '', ['required', 'email'], 'Email', '', 'Your email is required.');

  if($form->validate()) // Did the form validate successfully?
  {
    // Get data: $form->get('name'); ...
    // Success ! Send an email or register user in a database somewhere...
    $form->reset(); // Reset to default form.
  }
?>
<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" type="text/css" media="screen" href="css/simplephpform_default.css" />
  </head>
  <body>
    <?php echo $form->display(); ?>
  </body>
</html> 

🎁 Installation

This is a zero dependency library.

Just drag SimplePHPForm.php into your project and require('SimplePHPForm.php');

Optionally add the assets from examples/css and examples/images to your project.

👁️ Examples + Screenshot

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

Simple PHP Form Example 1

Keywords

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