i often use this form template when i want to create a new form
<style type="text/css">
<!--
form#checkout div.row div.field
{
float: left;
width: 250px;
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
}
div.clear
{
clear: both;
}
b {
color: #000000;
}
-->
</style>
<?
$num_fields = 18;
function tidy ($form_string) {
$form_string = trim(stripslashes($form_string));
return $form_string;
}
?>
<form action="" method="post" id="checkout">
<?
$field_name = array(
1 => 'Company Name:(if any)',
2 => 'First Name',
3 => 'Last Name',
4 => 'Street',
5 => 'City',
6 => 'State/ Providence',
7 => 'Country',
8 => 'Zip/Postal Code',
9 => 'Phone',
10 => 'E-Mail',
11=> 'Confirm E-Mail',
12 => '<p> </p>',
13 => 'Password',
14 => 'Confirm Password',
15=> 'Secret Question',
16 => 'Answer',
17 => 'Confirmation Key',
18 => 'Agree To Terms of Service'
);
$field_type = array(
1 => 'text',
2 => 'text',
3 => 'text',
4 => 'text',
5 => 'select',
6 => 'select',
7 => 'text',
8 => 'text',
9 => 'text',
10 => 'text',
11=> 'text',
12 => 'break',
13 => 'password',
14 => 'password',
15 => 'text',
16 => 'text',
17 => 'text',
18 => 'checkbox'
);
for($counter =1; $counter <= $num_fields ; $counter++)
{
echo '<div class="row"><div class="field">'.$field_name[$counter].'</div>';
switch($field_type[$counter])
{
case 'textarea':
echo '<textarea name="user['.$counter.']">'.$_POST['user'][$counter].'</textarea>';
break;
case 'checkbox':
echo '<input type="'.$field_type[$counter].'" name="user['.$counter.']" value="'.$_POST['user'][$counter].'">';
break;
case 'radiobutton':
echo '<input type="'.$field_type[$counter].'" name="user['.$counter.']" value="'.$_POST['user'][$counter].'">';
break;
case 'select':
echo'
<select name="question" >
<option value="What is your favorite pet's name?">What is your favorite pet's name?</option>
<option value="What is your father's birth date?">What is your father's birth date?</option>
<option value="What is your favorite music band?">What is your favorite music band?</option>
<option value="What is your mother's maiden name?">What is your mother's maiden name?</option>
</select>
';
break;
case 'file':
echo '<input type="'.$field_type[$counter].'" name="user['.$counter.']" value="'.$_POST['user'][$counter].'">';
break;
case 'hidden':
echo '<input type="'.$field_type[$counter].'" name="user['.$counter.']" value="'.$_POST['user'][$counter].'">';
break;
case 'break':
break;
default:
echo '<input type="'.$field_type[$counter].'" name="user['.$counter.']" value="'.$_POST['user'][$counter].'">';
break;
}
echo'</div><div class="clear"></div></div>';
}
?>
<input type=submit name="Submit" value="Submit" />
</form>
<?php
// The data comes from the form in fig 4.2
if(isset($_REQUEST['Submit']))
{
foreach($_POST['user'] as $key => $line) {
$user = tidy($line);
print("n<br />User[" . $key . '] ' . $user);
}
}
?>
Php Form Using Array For Field Name Template User Information
Php Form Using Array For Field Name Template User Information
Php Form Using Array For Field Name Template User Information
Post Description:
Post Tags: php, form, using, array, for, field, name, template, user, information
This Post Has Been Viewed 266 Times Since Fri Nov 23, 2007 8:48 am Posted By hostman with 0 replies
Post Description:
Post Tags: php, form, using, array, for, field, name, template, user, information
This Post Has Been Viewed 266 Times Since Fri Nov 23, 2007 8:48 am Posted By hostman with 0 replies
| Php Form Using Array For Field Name Template User Information |
Leave Your Comments [ dejar commentarios ]
Comments and replies About Php Form Using Array For Field Name Template User Information
(0) Comments

