<?php
// ---------------------------------------------------------------------------
// Forms fields manipulator and generator by Alfred Reinold Baudisch <alfred@auriumsoft.com.br>
// Copyright © 2005 AuriumSoft - www.auriumsoft.com.br
// ---------------------------------------------------------------------------
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// ---------------------------------------------------------------------------
//
// ATTENTION!
// This example is the same as example.php with the exception that
// the template are imported from a file.
// This is very useful when you use a template engine in your site,
// like FastTemplate, etc..
// Check line 102 to see how to do this
// And check the file 'template.txt', it is exactly how your template file have to be
// For using Smarty and AuriumForm together, see smarty_integration.txt
//
// Import AuriumForm class
require 'class.auriumform.php';
//
// Form posted, check data
// JUST FOR DEMONSTRANTION! VERY SIMPLE CHECKING!!
//
if($_POST['action'] == 'send')
{
$Errors = array();
if($_FILES['photo']['size'] == 0)
{
$Errors['photo'][] = 'Send your photo!';
}
if(!$_POST['fullname'])
{
$Errors['name'][] = 'Fill your name';
}
if(!$_POST['email'])
{
$Errors['email'][] = 'Fill your email';
}
elseif(!eregi('@', $_POST['email']))
{
$Errors['email'][] = 'Invalid E-mail!';
}
if(strlen($_POST['email']) > 30)
{
$Errors['email'][] = 'E-mail too long';
}
if(!$_POST['sex'])
{
$Errors['sex'][] = 'Select your genre';
}
if(!eregi('([0-9]+)', $_POST['pass']))
{
$Errors['pass'][] = 'Your password must have numbers!';
$Errors['pass'][] = 'Example: 123456';
}
if(!$_POST['comments'])
{
$Errors['comments'][] = 'Fill Comments';
}
elseif(strlen($_POST['comments']) < 50)
{
$Errors['comments'][] = 'Fill more comments';
}
}
//
// Configuration of the class
//
$Config = array(
// Default fields size
'size' => 35,
// Default fields css
'css' => 'fields',
// Default fields error css
'css_error' => 'fields_error',
// Import the template from a FILE.
// For in case you are using a template engine (ex: Smarty)
'template_file' => 'template.txt'
);
// Start the class, sending the config array
$Form =& new AuriumForm($Config);
echo '
<link rel="stylesheet" type="text/css" href="example.css">
<table border="0" cellpadding="4" cellspacing="0" align="center">
<tr><th>AuriumForm Example #2</th></tr>
<tr><td align="center" class="td_border">
<!--FORM HERE-->
';
// Start form with default values
// method=post, action=PHP_SELF
echo $Form->OpenForm(array('upload'=>true));
echo '
<table border="0" cellpadding="4" cellspacing="0" align="center">
';
//
// Set the fields
//
// Hidden field
$Hidden = array(
'type' => 'hidden',
'name' => 'action',
'value' => 'send'
);
// Text box
$Name = array(
'label' => 'Full Name:',
'type' => 'text',
'name' => 'fullname',
'size' => 55, // It has it own size
'css' => 'css_name', // It has it own css
'value' => $_POST['fullname'],
'errors' => $Errors['name'],
'maxlength' => 40
);
// Text box
$Email = array(
'label' => 'E-mail:',
'type' => 'text',
'name' => 'email',
'value' => $_POST['email'],
'errors' => $Errors['email']
);
// Text box
$City = array(
'label' => 'City:',
'type' => 'text',
'name' => 'city',
'value' => $_POST['city'],
'extras' => 'onFocus="alert(\'Type your city\');"'
);
// Radio
$Sex = array(
'label' => 'Genre:',
'type' => 'radio',
'name' => 'sex',
'value' => array('m','f'),
'text' => array('Masculine','Feminine'),
'selected' => $_POST['sex'],
'css' => false, // No css!
'css_error'=> false, // No error css!
'errors' => $Errors['sex']
);
// Checkbox
$Books = array(
'label' => 'Types of Books:',
'type' => 'checkbox',
'name' => 'books[]',
'value' => array('act', 'fic', 'rom', 'adventure'),
'text' => array('Action', 'Fiction', 'Romance', 'Adventure'),
'css' => false, // No css!
'id' => 'books',
'selected' => $_POST['books']
);
// Multiple choices selectbox
$Movies = array(
'label' => 'Type of Movies:',
'type' => 'selectbox',
'name' => 'movies[]',
'items' => array('act'=>'Action', 'fic'=>'Fiction', 'rom'=>'Romance',
'adventure'=>'Adventure', 'docu'=>'Documentary', 'political'=>'Political Views'),
'selected' =>$_POST['movies'],
'extras' => 'multiple'
);
// Selectbox
$Contact = array(
'label' => 'Type of Contact:',
'type' => 'selectbox',
'name' => 'contact',
'items' => array('email'=>'E-mail', 'phone'=>'Telephone', 'cel'=>'Cellphone'),
'selected' => $_POST['contact'],
);
// Single checkbox
$Agree = array(
'label' => 'Agree?',
'type' => 'checkbox',
'name' => 'agree',
'value' => 'yes',
'text' => 'Yes',
'css' => false,
'selected' => $_POST['agree']
);
// Textarea
$Comments = array(
'label' => 'Comments:',
'type' => 'textarea',
'name' => 'comments',
'size' => array(40, 6),
'value' => $_POST['comments'],
'css' => 'css_comments', // it own css
'css_error' => 'fields_error_comments', // it own error css
'errors' => $Errors['comments']
);
// Passwordbox
$Password = array(
'label' => 'Password:',
'type' => 'password',
'name' => 'pass',
'value' => $_POST['pass'],
'size' => 20,
'errors' => $Errors['pass'],
'maxlength' => 4
);
// Upload File
$Photo = array(
'label' => 'Photo:',
'type' => 'file',
'name' => 'photo',
'size' => 25,
'errors' => $Errors['photo']
);
// Button
$ButtonsTest = array(
'label' => 'Functions:',
'type' => 'button',
'value' => 'JavaScript',
'subtype' => 'button',
'extras' => 'onClick="alert(\'Button Clicked\');"'
);
// Buttons
$Buttons = array(
'type' => 'button',
'subtype' => array('submit','reset'),
'value' => array('Send Form','Reset Form'),
'alone' => true
);
// Image Button
$ImageButton = array(
'alone' => true,
'type' => 'image',
'src' => 'http://static.php.net/www.php.net/images/php.gif',
'value' => 'value',
'name' => 'name',
'size' => array(120, 67) // array(width, height)
);
//--------END SETTING FIELDS----------
// Send the fields to the class
$Form->SetData(
array($Hidden, $Name, $Email, $City, $Sex, $ButtonsTest, $Books, $Movies,
$Contact, $Agree, $Comments, $Password, $Photo, $ImageButton, $Buttons)
);
// Show fields
echo $Form->ShowFields();
//
// Add another field, but alone
//
if(!$_POST['date'])
{
$_POST['date'] = 'Actual Date';
}
$Date = array(
'label' => 'Date:',
'type' => 'text',
'name' => 'date',
'size' => 15,
'value' => $_POST['date']
);
echo $Form->OneField($Date);
echo '
</table>
';
echo $Form->CloseForm();
echo '
<!--END FORM-->
</td></tr>
</table>
<BR><BR><CENTER><font class="footer">By Alfred Reinold Baudisch (<a href="mailto:alfred@auriumsoft.com.br">alfred@auriumsoft.com.br</a>) - February, 12 - 2005 - <a href="http://www.auriumsoft.com.br">www.auriumsoft.com.br</a>.<BR></font></CENTER>
';
?>
|