<?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
// ---------------------------------------------------------------------------
// 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';
}
if(!$_POST['agree'])
{
$Errors['agree'][] = 'You must agree!';
}
}
//
// Configuration of the class
//
$Config = array(
// Default fields size
'size' => 35,
// Default fields css
'css' => 'fields',
// Default fields error css
'css_error' => 'fields_error',
'template_open' => '<tr>',
'template_label' => '<td valign="top" align="right">' . AURIUMFORM_TP_LABEL . '</td>',
'template_field' => '<td>' . AURIUMFORM_TP_FIELD,
'template_error' => '<BR><font class="error">- ' . AURIUMFORM_TP_ERROR . '</font>',
'template_close' => '</td></tr>',
'template_line' => "\n",
'template_field_one' => '<tr><td colspan="2" align="center">' . AURIUMFORM_TP_LABEL . AURIUMFORM_TP_FIELD . '</td></tr>'
);
// 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 #1</th></tr>
<tr><td align="center" class="td_border">
<!--FORM HERE-->
';
// Start form using aliases m (for method) and p (for post)
// action=PHP_SELF
echo $Form->OpenForm(array('upload'=>true, 'm'=>'p'));
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
// Using aliases
$Email = array(
'l' => 'E-mail:',
't' => 'text',
'n' => 'email',
'v' => $_POST['email'],
'e' => $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'),
'text_clickable' => true,
'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',
'text_clickable' => true,
'css' => false,
'selected' => $_POST['agree'],
'errors' => $Errors['agree'],
'css_error' => false
);
// 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:',
't' => '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>
';
echo $Form->OpenForm();
echo '<BR><BR>';
$Form->Debug();
?>
|