PHP Class To Build HTML Forms
Posted on : 29-04-2011 | By : TheBizzTech | In : Github, HTML, PHP, Programming
Tags: Code, Forms, HTML, PHP, PHP 5, Programming
3
I have recently pushed a new repository to Github to showcase a PHP class I built. This class helps make building HTML forms easier. I originally built this class to help make PayPal buttons easier to built into PHP scripts. I have not looked at this script much since the summer of 2010, but hope to dust it off soon.
Here is a simple example of how to use the class that you can download from Github here, https://github.com/thebizztech/htmlform
<?php
/**
* TheBizzTech
*
* This example utilizes the open source htmlform PHP class built to make building HTML forms easier
*
* @author Jason Michels
* @link http://thebizztech.com
*/
//To use the htmlform class you first need to include the file
require("htmlform.php");
?>
<html>
<body>
<?php
// Initialize form class
$form = new htmlform();
// Begin the form and pass array of values
$form->begin_form(array("name"=>"myform","action"=>"index.php","method"=>"post","target"=>"thebizztech"));
// To create a new label include the element id in the "for" array value
$form->form_label(array("for"=>"1stid","text"=>"This is a label: "));
// To create an input field pass array with any standard attributes. The class will check to see which ones are set
$form->form_input(array("type"=>"text","id"=>"1stid","class"=>"1stclass","name"=>"1stname","value"=>"this is the value"));
// Another form input example
$form->form_input(array("type"=>"submit","id"=>"submitform","class"=>"submitform","name"=>"submit","value"=>"Submit Form"));
// Example of a form button
$form->form_button(array("type"=>"button","value"=>"Awesome","text"=>"Awesome button"));
// End of form. This will take one parameter allowing you to add html after the form such as a line in the example
$form->end_form("<hr />");
?>
</body>
</html>

