Skip to content

Instantly share code, notes, and snippets.

@whatnickcodes
Created December 5, 2012 19:55
Show Gist options
  • Save whatnickcodes/4218941 to your computer and use it in GitHub Desktop.
Save whatnickcodes/4218941 to your computer and use it in GitHub Desktop.
lazy form
<?php
$form_info = array(
array(
'credit_card_type' => array(
'Credit Card Type',
array(
'visa' => 'VISA',
'mc' => 'Master Card',
'amex' => 'American Express',
'discover' => 'Discover'
)
)
),
array(
'account' => 'Credit Card Number',
'exp' => 'Expiration Date',
'cvv2' => 'CVV',
'email' => 'Email',
'business' => 'Business'
),
array(
'salutation' => array(
'Salutation',
array(
'' => '',
'mr' => 'Mr.',
'mrs' => 'Mrs.',
'ms' => 'Ms'
)
)
),
array(
'first_name' => 'First Name',
'last_name' => 'Last Name'
),
array(
'suffix' => array(
'Suffix',
array(
'' => '',
'Jr.' => 'Jr.',
'Sr.' => 'Sr.',
'II.' => 'II',
'III' => 'III',
'IIV' => 'IIV',
'V' => 'V'
)
)
),
array(
'street' => 'Billing Street Address',
'street2' => 'Billing Street Address 2',
'city' => 'Billing City'
),
array(
'state' => array(
'Billing State',
$this->config->item('states')
),
'countrycode' => array(
'Billing Country Code',
$this->config->item('countries')
)
),
array(
'zip' => 'Billing Zip',
'phonenum' => 'Billing Phone Number'
)
);
echo form_open('cod/form_page');
$i = 1;
foreach ($form_info as $group) :
if ($i == 1 || $i == 3 || $i == 5 || $i == 7)
{
foreach ($group as $key => $value)
{
echo form_label($value[0], $key);
echo form_error($key, '<div class="error-message">', '</div>');
echo form_dropdown($key, $value[1], set_value($key));
}
}
if ($i == 2 || $i == 4 || $i == 6 || $i == 8)
{
foreach ($group as $key => $value)
{
echo form_label($value, $key);
$form_array = array(
'name' => $key,
'id' => $value,
'value' => set_value($value)
);
if (form_error($key)) $form_array['class'] = 'error';
echo form_error($key, '<div class="error-message">', '</div>');
echo form_input($form_array);
}
}
$i++;
endforeach;
echo form_submit('Submit', 'submit');
echo form_close();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment