Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //form.php
- <?php
- use Zend_Form as ZendForm,
- Zend_Form_Element_Hidden as HiddenField,
- Zend_Form_Element_Text as InputField,
- Zend_Form_Element_Select as DropdownField,
- Zend_Form_Element_Textarea as TextArea;
- class CollectionForm extends ZendForm {
- public function init() {
- $card = new \Zend_Form_SubForm;
- $card->setElementsBelongTo('Card');
- $fields['CardNumber'] = new InputField('CardNumber',array('required'=>true));
- $fields['ExpirationMonth'] = new InputField('ExpirationMonth',array('required'=>true));
- $fields['ExpirationYear'] = new InputField('ExpirationYear',array('required'=>true));
- $fields['SecurityCode'] = new InputField('SecurityCode',array('required'=>true));
- $fields['NameOnAccount'] = new InputField('NameOnAccount',array('required'=>true));
- foreach ($fields as $field) {
- $card->addElement($field);
- }
- $address = new \Zend_Form_SubForm;
- $address->setElementsBelongTo('Address',array('required'=>true));
- $fields = array();
- $fields['Street'] = new InputField('Street',array('required'=>true));
- $fields['City'] = new InputField('City',array('required'=>true));
- $fields['State'] = new InputField('State',array('required'=>true));
- $fields['Zip'] = new InputField('Zip',array('required'=>true));
- $fields['Country'] = new InputField('Country',array('required'=>true));
- foreach ($fields as $field) {
- $address->addElement($field);
- }
- $card->addSubForm($address,'Address');
- $this->addSubForm($card,'Card');
- $fields = array();
- $fields['entryID'] = new HiddenField('eventID');
- $fields['registrationID'] = new HiddenField('registrationID');
- foreach ($fields as $field) {
- $this->addElement($field);
- }
- }
- }
- //index.php
- $form = new CollectionForm;
- $form->Card->ExpirationMonth = new Zend_Form_Element_Select('ExpirationMonth');
- $form->Card->ExpirationMonth->addMultiOptions(array(
- "01"=>"01",
- "02"=>"02",
- "03"=>"03",
- "04"=>"04",
- "05"=>"05",
- "06"=>"06",
- "07"=>"07",
- "08"=>"08",
- "09"=>"09",
- 10=>"10",
- 11=>"11",
- 12=>"12"));
- $form->Card->ExpirationYear = new Zend_Form_Element_Select('ExpirationYear');
- $years = range(date('Y'),date('Y')+10);
- foreach($years as $year) {
- $options[$year] = $year;
- }
- $form->Card->ExpirationYear->addMultiOptions($options);
- $form->Card->Address->State = new Zend_Form_Element_Select('State');
- $form->Card->Address->State->addMultiOptions(array(
- "AL" => "Alabama",
- "AK" => "Alaska",
- "AZ" => "Arizona",
- "AR" => "Arkansas",
- "CA" => "California",
- "CO" => "Colorado",
- "CT" => "Connecticut",
- "DE" => "Delaware",
- "DC" => "District of Columbia",
- "FL" => "Florida",
- "GA" => "Georgia",
- "HI" => "Hawaii",
- "ID" => "Idaho",
- "IL" => "Illinois",
- "IN" => "Indiana",
- "IA" => "Iowa",
- "KS" => "Kansas",
- "KY" => "Kentucky",
- "LA" => "Louisiana",
- "ME" => "Maine",
- "MD" => "Maryland",
- "MA" => "Massachusetts",
- "MI" => "Michigan",
- "MN" => "Minnesota",
- "MS" => "Mississippi",
- "MO" => "Missouri",
- "MT" => "Montana",
- "NE" => "Nebraska",
- "NV" => "Nevada",
- "NH" => "New Hampshire",
- "NJ" => "New Jersey",
- "NM" => "New Mexico",
- "NY" => "New York",
- "NC" => "North Carolina",
- "ND" => "North Dakota",
- "OH" => "Ohio",
- "OK" => "Oklahoma",
- "OR" => "Oregon",
- "PA" => "Pennsylvania",
- "RI" => "Rhode Island",
- "SC" => "South Carolina",
- "SD" => "South Dakota",
- "TN" => "Tennessee",
- "TX" => "Texas",
- "UT" => "Utah",
- "VT" => "Vermont",
- "VA" => "Virginia",
- "WA" => "Washington",
- "WV" => "West Virginia",
- "WI" => "Wisconsin",
- "WY" => "Wyoming",
- "NA" => "Not applicable"
- )
- );
- $form->setView($view);
- $view->assign('form',$form);
- $view->setScriptPath('.');
- $form->addElement('hidden','token');
- $view->cost = $_SESSION['cost'];
- $view->item = $_SESSION['package'];
- //form.phtml
- <?php
- $form = $this->element;
- function addErrorsClass($form) {
- foreach($form as $item) {
- if ($item instanceof Zend_Form) {
- addErrorsClass($item);
- }
- else {
- if ($item->hasErrors()) {
- $item->setAttrib('class','error');
- }
- }
- }
- }
- addErrorsClass($form);
- $view = $form->getView();
- function addView($form) {
- global $view;
- foreach($form as $item) {
- if ($item instanceof Zend_Form) {
- $item->setView($view);
- addView($item);
- }
- else {
- $item->setView($view);
- }
- }
- }
- addView($form);
- ?>
- <div class="container">
- <form id="checkoutForm" class="" action="" method="post">
- <?php echo $form->token->renderViewHelper()?>
- <div class="ib-cont row r">
- <label class="ib">Name on Card</label>
- <div class="ib input-wrapper">
- <?php echo $form->Card->NameOnAccount->renderViewHelper()?>
- </div>
- </div>
- <div class="ib-cont row r">
- <label class="ib">Credit Card No</label>
- <div class="ib input-wrapper">
- <?php echo $form->Card->CardNumber->renderViewHelper()?>
- </div>
- </div>
- <div class="ib-cont row">
- <label class="ib">Expiration</label>
- <div class="ib input-wrapper month">
- <?php echo $form->Card->ExpirationMonth->renderViewHelper()?>
- </div><!--
- --><div class="ib input-wrapper year">
- <?php echo $form->Card->ExpirationYear->renderViewHelper()?>
- </div>
- </div>
- <div class="ib-cont row">
- <label class="ib">CVV</label>
- <div class="ib input-wrapper">
- <?php echo $form->Card->SecurityCode->renderViewHelper()?>
- </div>
- </div>
- <div class="ib-cont row">
- <label class="ib">Address</label>
- <?php echo $form->Card->Address->Street->setBelongsTo('Card[Address]')->renderViewHelper()?>
- </div>
- <div class="ib-cont row">
- <label class="ib">City</label>
- <div class="ib input-wrapper">
- <?php echo $form->Card->Address->City->setBelongsTo('Card[Address]')->renderViewHelper()?>
- </div>
- </div>
- <div class="ib-cont row state">
- <label class="ib">State</label>
- <div class="ib input-wrapper">
- <?php echo $form->Card->Address->State->setBelongsTo('Card[Address]')->renderViewHelper()?>
- </div>
- </div>
- <div class="ib-cont row">
- <label class="ib">Country</label>
- <div class="ib input-wrapper">
- <?php echo $form->Card->Address->Country->setBelongsTo('Card[Address]')->renderViewHelper()?>
- </div>
- </div>
- <div class="ib-cont row">
- <label class="ib">Zip</label>
- <div class="ib input-wrapper">
- <?php echo $form->Card->Address->Zip->setBelongsTo('Card[Address]')->renderViewHelper()?>
- </div>
- </div>
- <div class="ib-cont row">
- <div class="ib secure">
- <ins class="ib sprite lock"></ins>
- <span>Pay using our secure server</span>
- </div>
- <div class="ib input-wrapper submit">
- <input id="Button1" type="submit" name="Submit" value="Checkout" class="button" />
- </div>
- </div>
- </form>
- </div>
- //index.phtml
- <?php
- echo $this->form->setDecorators( array(
- 'PrepareElements',
- array('ViewScript', array(
- 'viewScript' => 'form.phtml'))))->render($this);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement