Acedeal
June 6th, 2003, 03:21
A better example
This is hard to debug;
<?php
<html>
<head>
<title>-=DoW=- Recruiting Forms</title>
<link rel="stylesheet" href="css/pof/green.css" type="text/css">
</head>
<bgcolor="#000000">
<body>
<div align="center">
<?php
require "lib/FormProcessor.class.php";
include "inc/countries.inc.php";
// Initialize
$fp = new FormProcessor("lib/");
// Import the needed elements
$fp->importElements(array(
FPText, FPTextField, FPTextArea, FPPassword, FPSelect,
FPFile, FPCheckBox, FPRadio, FPSubmitButton,
'extra/FPConfirmPassword'
));
$fp->importLayouts(array( FPColLayout, FPRowLayout, FPGridLayout, FPGroup ));
$fp->importWrappers(array( FPLeftTitleWrapper ));
// Create the form object
$myForm = new FPForm(array(
title => '-=DoW=- Recruiting',
name => 'myForm',
action => $PHP_SELF,
display_outer_table => true,
refine_owners => true,
table_align => 'center',
table_width => '500'
));
// Wrappers
$leftWrapper = new FPLeftTitleWrapper(array());
//$WEAPONS = ;
// Construct a grid of radio elements
$radioGrid = new FPGridLayout(array(
table_padding => 7,
columns => 3,
));
$i = 0;
foreach (
array(
'SVD', 'M24', 'M82', 'MOS',
'M16', 'Nade Laucher', 'Saw')
as $weapon
)
$radioGrid->addElement(
new FPRadio(
array(
group_name => 'radio_group',
item_value => $i,
title => $weapon,
checked => ($i++ == 0)
))
);
// Construct a grid of checkbox elements
$checkboxGrid = new FPGridLayout(array(
table_padding => 5,
columns => 2,
));
$i = 0;
foreach (
array(
'DoW_1','DoW_II','DoW_III','DoW_IV','DOW_V','DOW_V I',
'DOW_VII','Homelan','Other Private Servers','Only -=DoW=-' )
as $server
)
$checkboxGrid->addElement(
new FPCheckBox(
array(
name => 'checkbox'.$i,
title => $server,
table_align => 'left',
table_padding => 0,
checked => (++$i)%2,
comment => 'Check it if you if you play on it!'
))
);
// Password field
// We have to create an explicit reference to this object to use it
// in the FPConfirmPassword object constructor
$passwordField = new FPPassword(
array(
name => 'password',
title => 'Password',
required => true,
size => 20,
valid_RE => FP_VALID_PASSWORD,
max_length => 36,
wrapper => &$leftWrapper,
comment =>
'Password is case sensitive and must be '.
'at least 6 characters!'
));
// Define form elements
$myForm->setBaseLayout(
new FPColLayout(array(
table_padding => 5,
element_align => center,
elements => array(
new FPText(
array(
text =>
'<div align="left">'.
'Please, fill in the following fields.'.'<br>'.
'Read the comments carefully before submitting '.
'your data!'.
'</div>'
)),
new FPGroup(array(
title => '-=DoW=- <br>Recruiting Application',
elements => array(new FPRowLayout(array(
elements => array(
new FPTextField(array(
name => forum_name,
title => 'Forum_Name',
wrapper => &$leftWrapper,
size => 20,
css_style => 'width:150px;',
required => true,
max_length => 256
)),
),
comment =>
'You first need to '.
'<a href="/forum/profile.php?mode=register&sid=b869f3bf803a1a4a960852e56d095beflogin.php">'.
'have a Forum Account'.
'</a> '.
'before sending<br>an Application to Recruitment'
))),
)),
new FPTextField(
array(
name => 'game_name',
title => 'Game Name',
required => true,
size => 33,
max_length => 256,
wrapper => &$leftWrapper
)),
new FPTextField(
array(
name => 'email',
title => 'E-mail Address',
comment => 'We do not Accept any Applications from @yahoo or @hotmail Accounts'.
' or any other Free Email Type Accounts.'.
'<br>'.
'You will need to have a Real Email Account',
required => true,
size => 33,
max_length => 256,
wrapper => &$leftWrapper
)),
new FPTextField(
array(
name => 'first_name',
title => 'First Name',
comment =>
'First name must be shorter than 36 '.
'symbols and start with a letter',
required => true,
size => 25,
max_length => 36,
wrapper => &$leftWrapper
)),
new FPTextField(
array(
name => 'last_name',
title => 'Last Name',
required => true,
size => 25,
valid_RE => FP_VALID_NAME,
max_length => 36,
wrapper => &$leftWrapper,
)),
new FPSelect(
array(
name => 'country',
title => 'Your Country',
multiple => false,
options => $COUNTRIES,
selected => array("RUS"),
css_style => 'width:200px;',
wrapper => &$leftWrapper
)),
new FPSelect(
array(
name => 'favourite_countries',
title => 'Your Favourite Countries',
multiple => true,
min_options_selection => 2,
max_options_selection => 4,
comment => 'You must select between 2 and 4 options',
options => $COUNTRIES,
selected => array("GBR"),
css_style => 'width:200px;',
wrapper => &$leftWrapper
)),
new FPGroup(
array(
title => 'Choose Your Favourite Weapon',
table_align => center,
table_padding => 7,
elements => array(
&$radioGrid
)
)),
new FPTextArea(
array(
name => 'comments',
title => 'Reason Why you Think you would be a good fit in -=DoW=-',
max_length => 2048,
required => true,
wrapper => &$leftWrapper
)),
new FPGroup(
array(
title => 'What Server or Servers do you Normally Play on',
table_align => center,
table_padding => 7,
elements => array(
&$checkboxGrid,
)
// )),
//
//new FPFile(
//array(
//name => 'image',
// title => 'Your Image (optional)',
//size => '20',
/* destination_file =>
'/var/www/html/tests/pof/upload/upload.gif', */
//allowable_content_types => array('image/gif'),
//max_file_size => 20480,
//wrapper => &$leftWrapper,
//comment =>
//'Only GIF images with size less than 20K '.
//'are allowed for uploading'
)),
new FPCheckBox(
array(
name => 'subscribe_chkbox',
title => 'Have you Read and Understand all of -=DoW=- Rules',
table_align => 'center',
checked => False
)),
new FPRowLayout(array(
table_align => center,
table_padding => 20,
elements => array(
new FPSubmitButton(
array(
name => 'submit',
title => ' Submit '
)),
)
)),
)
))
);
// Obtain submitted data and check the values correctness
if ($myForm->getSubmittedData() && $myForm->isDataValid()) {
$elements = $myForm->getElementValues();
echo
'<div align="left">'.
'Thank you, your data is valid!'.
'<pre>'
;
var_dump($elements);
echo
'</pre>'.
'</div>';
} else
$myForm->display();
?>
</div>
</body>
</html>
And using the php tags makes it much easier..
same code using the php tags
[php:1:5966474cb8]
<?php
<html>
<head>
<title>-=DoW=- Recruiting Forms</title>
<link rel="stylesheet" href="css/pof/green.css" type="text/css">
</head>
<bgcolor="#000000">
<body>
<div align="center">
<?php
require "lib/FormProcessor.class.php";
include "inc/countries.inc.php";
// Initialize
$fp = new FormProcessor("lib/");
// Import the needed elements
$fp->importElements(array(
FPText, FPTextField, FPTextArea, FPPassword, FPSelect,
FPFile, FPCheckBox, FPRadio, FPSubmitButton,
'extra/FPConfirmPassword'
));
$fp->importLayouts(array( FPColLayout, FPRowLayout, FPGridLayout, FPGroup ));
$fp->importWrappers(array( FPLeftTitleWrapper ));
// Create the form object
$myForm = new FPForm(array(
title => '-=DoW=- Recruiting',
name => 'myForm',
action => $PHP_SELF,
display_outer_table => true,
refine_owners => true,
table_align => 'center',
table_width => '500'
));
// Wrappers
$leftWrapper = new FPLeftTitleWrapper(array());
//$WEAPONS = ;
// Construct a grid of radio elements
$radioGrid = new FPGridLayout(array(
table_padding => 7,
columns => 3,
));
$i = 0;
foreach (
array(
'SVD', 'M24', 'M82', 'MOS',
'M16', 'Nade Laucher', 'Saw')
as $weapon
)
$radioGrid->addElement(
new FPRadio(
array(
group_name => 'radio_group',
item_value => $i,
title => $weapon,
checked => ($i++ == 0)
))
);
// Construct a grid of checkbox elements
$checkboxGrid = new FPGridLayout(array(
table_padding => 5,
columns => 2,
));
$i = 0;
foreach (
array(
'DoW_1','DoW_II','DoW_III','DoW_IV','DOW_V','DOW_V I',
'DOW_VII','Homelan','Other Private Servers','Only -=DoW=-' )
as $server
)
$checkboxGrid->addElement(
new FPCheckBox(
array(
name => 'checkbox'.$i,
title => $server,
table_align => 'left',
table_padding => 0,
checked => (++$i)%2,
comment => 'Check it if you if you play on it!'
))
);
// Password field
// We have to create an explicit reference to this object to use it
// in the FPConfirmPassword object constructor
$passwordField = new FPPassword(
array(
name => 'password',
title => 'Password',
required => true,
size => 20,
valid_RE => FP_VALID_PASSWORD,
max_length => 36,
wrapper => &$leftWrapper,
comment =>
'Password is case sensitive and must be '.
'at least 6 characters!'
));
// Define form elements
$myForm->setBaseLayout(
new FPColLayout(array(
table_padding => 5,
element_align => center,
elements => array(
new FPText(
array(
text =>
'<div align="left">'.
'Please, fill in the following fields.'.'
'.
'Read the comments carefully before submitting '.
'your data!'.
'</div>'
)),
new FPGroup(array(
title => '-=DoW=-
Recruiting Application',
elements => array(new FPRowLayout(array(
elements => array(
new FPTextField(array(
name => forum_name,
title => 'Forum_Name',
wrapper => &$leftWrapper,
size => 20,
css_style => 'width:150px;',
required => true,
max_length => 256
)),
),
comment =>
'You first need to '.
'<a href="/forum/profile.php?mode=register&sid=b869f3bf803a1a4a960852e56d095beflogin.php">'.
'have a Forum Account'.
'</a> '.
'before sending
an Application to Recruitment'
))),
)),
new FPTextField(
array(
name => 'game_name',
title => 'Game Name',
required => true,
size => 33,
max_length => 256,
wrapper => &$leftWrapper
)),
new FPTextField(
array(
name => 'email',
title => 'E-mail Address',
comment => 'We do not Accept any Applications from @yahoo or @hotmail Accounts'.
' or any other Free Email Type Accounts.'.
'
'.
'You will need to have a Real Email Account',
required => true,
size => 33,
max_length => 256,
wrapper => &$leftWrapper
)),
new FPTextField(
array(
name => 'first_name',
title => 'First Name',
comment =>
'First name must be shorter than 36 '.
'symbols and start with a letter',
required => true,
size => 25,
max_length => 36,
wrapper => &$leftWrapper
)),
new FPTextField(
array(
name => 'last_name',
title => 'Last Name',
required => true,
size => 25,
valid_RE => FP_VALID_NAME,
max_length => 36,
wrapper => &$leftWrapper,
)),
new FPSelect(
array(
name => 'country',
title => 'Your Country',
multiple => false,
options => $COUNTRIES,
selected => array("RUS"),
css_style => 'width:200px;',
wrapper => &$leftWrapper
)),
new FPSelect(
array(
name => 'favourite_countries',
title => 'Your Favourite Countries',
multiple => true,
min_options_selection => 2,
max_options_selection => 4,
comment => 'You must select between 2 and 4 options',
options => $COUNTRIES,
selected => array("GBR"),
css_style => 'width:200px;',
wrapper => &$leftWrapper
)),
new FPGroup(
array(
title => 'Choose Your Favourite Weapon',
table_align => center,
table_padding => 7,
elements => array(
&$radioGrid
)
)),
new FPTextArea(
array(
name => 'comments',
title => 'Reason Why you Think you would be a good fit in -=DoW=-',
max_length => 2048,
required => true,
wrapper => &$leftWrapper
)),
new FPGroup(
array(
title => 'What Server or Servers do you Normally Play on',
table_align => center,
table_padding => 7,
elements => array(
&$checkboxGrid,
)
// )),
//
//new FPFile(
//array(
//name => 'image',
// title => 'Your Image (optional)',
//size => '20',
/* destination_file =>
'/var/www/html/tests/pof/upload/upload.gif', */
//allowable_content_types => array('image/gif'),
//max_file_size => 20480,
//wrapper => &$leftWrapper,
//comment =>
//'Only GIF images with size less than 20K '.
//'are allowed for uploading'
)),
new FPCheckBox(
array(
name => 'subscribe_chkbox',
title => 'Have you Read and Understand all of -=DoW=- Rules',
table_align => 'center',
checked => False
)),
new FPRowLayout(array(
table_align => center,
table_padding => 20,
elements => array(
new FPSubmitButton(
array(
name => 'submit',
title => ' Submit '
)),
)
)),
)
))
);
// Obtain submitted data and check the values correctness
if ($myForm->getSubmittedData() && $myForm->isDataValid()) {
$elements = $myForm->getElementValues();
echo
'<div align="left">'.
'Thank you, your data is valid!'.
'<pre>'
;
var_dump($elements);
echo
'</pre>'.
'</div>';
} else
$myForm->display();
?>
</div>
</body>
</html>
[/php:1:5966474cb8]
vBulletin® v3.8.3, Copyright ©2000-2012, Jelsoft Enterprises Ltd.