/** * * @return string */ function __toString() { // Generate the component div $componentDiv = $this->generateComponentDiv(); // Add the card type select tag if ($this->showCardType) { $cardTypeDiv = new JFormElement('div', array('class' => 'cardTypeDiv')); $cardType = new JFormElement('select', array('id' => $this->id . '-cardType', 'name' => $this->name . '-cardType', 'class' => 'cardType')); // Have a default value the drop down list if there isn't a sublabel if ($this->showSublabels == false) { $cardType->insert($this->getOption('', 'Card Type', true, true)); } // Add the card types foreach ($this->creditCardProviders as $key => $value) { $cardType->insert($this->getOption($key, $value, false, false)); } $cardTypeDiv->insert($cardType); } // Add the card number input tag $cardNumberDiv = new JFormElement('div', array('class' => 'cardNumberDiv')); $cardNumber = new JFormElement('input', array('type' => 'text', 'id' => $this->id . '-cardNumber', 'name' => $this->name . '-cardNumber', 'class' => 'cardNumber', 'maxlength' => '16')); $cardNumberDiv->insert($cardNumber); // Add the expiration month select tag $expirationDateDiv = new JFormElement('div', array('class' => 'expirationDateDiv')); $expirationMonth = new JFormElement('select', array('id' => $this->id . '-expirationMonth', 'name' => $this->name . '-expirationMonth', 'class' => 'expirationMonth')); // Have a default value the drop down list if there isn't a sublabel if ($this->showSublabels == false) { $expirationMonth->insert($this->getOption('', 'Month', true, true)); } // Add the months foreach (JFormComponentDropDown::getMonthArray() as $dropDownOption) { $optionValue = isset($dropDownOption['value']) ? $dropDownOption['value'] : ''; $optionLabel = isset($dropDownOption['label']) ? $dropDownOption['label'] : ''; $optionSelected = isset($dropDownOption['selected']) ? $dropDownOption['selected'] : false; $optionDisabled = isset($dropDownOption['disabled']) ? $dropDownOption['disabled'] : false; $optionOptGroup = isset($dropDownOption['optGroup']) ? $dropDownOption['optGroup'] : ''; if ($this->showMonthName) { $expirationMonth->insert($this->getOption($optionValue, $optionValue . ' - ' . $optionLabel, $optionSelected, $optionDisabled)); $expirationMonth->addClassName('long'); } else { $expirationMonth->insert($this->getOption($optionValue, $optionValue, $optionSelected, $optionDisabled)); } } $expirationDateDiv->insert($expirationMonth); // Add the expiration year select tag $expirationYear = new JFormElement('select', array('id' => $this->id . '-expirationYear', 'name' => $this->name . '-expirationYear', 'class' => 'expirationYear')); // Add years if ($this->showLongYear) { $startYear = Date('Y'); $expirationYear->addClassName('long'); } else { $startYear = Date('y'); if (!$this->showMonthName) { $expirationDateDiv->insert('<span class="expirationDateSeparator">/</span>'); } } if ($this->showSublabels == false) { $expirationYear->insert($this->getOption('', 'Year', true, true)); } foreach (range($startYear, $startYear + 6) as $year) { $expirationYear->insert($this->getOption($year, $year, false, false)); } $expirationDateDiv->insert($expirationYear); // Add the security code input tag $securityCodeDiv = new JFormElement('div', array('class' => 'securityCodeDiv')); $securityCode = new JFormElement('input', array('type' => 'text', 'id' => $this->id . '-securityCode', 'name' => $this->name . '-securityCode', 'class' => 'securityCode', 'maxlength' => '4')); $securityCodeDiv->insert($securityCode); // Set the empty values if they are enabled if (!empty($this->emptyValues)) { foreach ($this->emptyValues as $emptyValueKey => $emptyValue) { if ($emptyValueKey == 'cardNumber') { $cardNumber->setAttribute('value', $emptyValue); $cardNumber->addClassName('defaultValue'); } if ($emptyValueKey == 'securityCode') { $securityCode->setAttribute('value', $emptyValue); $securityCode->addClassName('defaultValue'); } } } // Put the sublabels in if the option allows for it if ($this->showSublabels) { if ($this->showCardType) { $cardTypeDiv->insert('<div class="jFormComponentSublabel"><p>Card Type</p></div>'); } $cardNumberDiv->insert('<div class="jFormComponentSublabel"><p>Card Number</p></div>'); $expirationDateDiv->insert('<div class="jFormComponentSublabel"><p>Expiration Date</p></div>'); if ($this->showSecurityCode) { $securityCodeDiv->insert('<div class="jFormComponentSublabel"><p>Security Code</p></div>'); } } // Insert the components if ($this->showCardType) { $componentDiv->insert($cardTypeDiv); } $componentDiv->insert($cardNumberDiv); $componentDiv->insert($expirationDateDiv); if ($this->showSecurityCode) { $componentDiv->insert($securityCodeDiv); } // Add any description (optional) $componentDiv = $this->insertComponentDescription($componentDiv); // Add a tip (optional) $componentDiv = $this->insertComponentTip($componentDiv); return $componentDiv->__toString(); }
/** * * @return string */ function __toString() { // Generate the component div $componentDiv = $this->generateComponentDiv(); // Add the Address Line 1 input tag $addressLine1Div = new JFormElement('div', array('class' => 'addressLine1Div')); $addressLine1 = new JFormElement('input', array('type' => 'text', 'id' => $this->id . '-addressLine1', 'name' => $this->name . '-addressLine1', 'class' => 'addressLine1')); $addressLine1Div->insert($addressLine1); // Add the Address Line 2 input tag $addressLine2Div = new JFormElement('div', array('class' => 'addressLine2Div')); $addressLine2 = new JFormElement('input', array('type' => 'text', 'id' => $this->id . '-addressLine2', 'name' => $this->name . '-addressLine2', 'class' => 'addressLine2')); $addressLine2Div->insert($addressLine2); // Add the city input tag $cityDiv = new JFormElement('div', array('class' => 'cityDiv')); $city = new JFormElement('input', array('type' => 'text', 'id' => $this->id . '-city', 'name' => $this->name . '-city', 'class' => 'city', 'maxlength' => '15')); $cityDiv->insert($city); // Add the State input tag $stateDiv = new JFormElement('div', array('class' => 'stateDiv')); if ($this->stateDropDown) { $state = new JFormElement('select', array('id' => $this->id . '-state', 'name' => $this->name . '-state', 'class' => 'state')); // Add any options that are not in an opt group to the select foreach (JFormComponentDropDown::getStateArray($this->selectedState) as $dropDownOption) { $optionValue = isset($dropDownOption['value']) ? $dropDownOption['value'] : ''; $optionLabel = isset($dropDownOption['label']) ? $dropDownOption['label'] : ''; $optionSelected = isset($dropDownOption['selected']) ? $dropDownOption['selected'] : false; $optionDisabled = isset($dropDownOption['disabled']) ? $dropDownOption['disabled'] : false; $optionOptGroup = isset($dropDownOption['optGroup']) ? $dropDownOption['optGroup'] : ''; $state->insert($this->getOption($optionValue, $optionLabel, $optionSelected, $optionDisabled)); } } else { $state = new JFormElement('input', array('type' => 'text', 'id' => $this->id . '-state', 'name' => $this->name . '-state', 'class' => 'state')); } $stateDiv->insert($state); // Add the Zip input tag $zipDiv = new JFormElement('div', array('class' => 'zipDiv')); $zip = new JFormElement('input', array('type' => 'text', 'id' => $this->id . '-zip', 'name' => $this->name . '-zip', 'class' => 'zip', 'maxlength' => '5')); $zipDiv->insert($zip); // Add the country input tag $countryDiv = new JFormElement('div', array('class' => 'countryDiv')); // Don't built a select list if you are United States only if ($this->unitedStatesOnly) { $country = new JFormElement('input', array('type' => 'hidden', 'id' => $this->id . '-country', 'name' => $this->name . '-country', 'class' => 'country', 'value' => 'US', 'style' => 'display: none;')); } else { $country = new JFormElement('select', array('id' => $this->id . '-country', 'name' => $this->name . '-country', 'class' => 'country')); // Add any options that are not in an opt group to the select foreach (JFormComponentDropDown::getCountryArray($this->selectedCountry) as $dropDownOption) { $optionValue = isset($dropDownOption['value']) ? $dropDownOption['value'] : ''; $optionLabel = isset($dropDownOption['label']) ? $dropDownOption['label'] : ''; $optionSelected = isset($dropDownOption['selected']) ? $dropDownOption['selected'] : false; $optionDisabled = isset($dropDownOption['disabled']) ? $dropDownOption['disabled'] : false; $optionOptGroup = isset($dropDownOption['optGroup']) ? $dropDownOption['optGroup'] : ''; $country->insert($this->getOption($optionValue, $optionLabel, $optionSelected, $optionDisabled)); } } $countryDiv->insert($country); // Set the empty values if they are enabled if (!empty($this->emptyValues)) { foreach ($this->emptyValues as $empyValueKey => $emptyValue) { if ($empyValueKey == 'addressLine1') { $addressLine1->setAttribute('value', $emptyValue); $addressLine1->addClassName('defaultValue'); } if ($empyValueKey == 'addressLine2') { $addressLine2->setAttribute('value', $emptyValue); $addressLine2->addClassName('defaultValue'); } if ($empyValueKey == 'city') { $city->setAttribute('value', $emptyValue); $city->addClassName('defaultValue'); } if ($empyValueKey == 'state' && !$this->stateDropDown) { $state->setAttribute('value', $emptyValue); $state->addClassName('defaultValue'); } if ($empyValueKey == 'zip') { $zip->setAttribute('value', $emptyValue); $zip->addClassName('defaultValue'); } } } // Put the sublabels in if the option allows for it if ($this->showSublabels) { $addressLine1Div->insert('<div class="jFormComponentSublabel"><p>Street Address</p></div>'); $addressLine2Div->insert('<div class="jFormComponentSublabel"><p>Address Line 2</p></div>'); $cityDiv->insert('<div class="jFormComponentSublabel"><p>City</p></div>'); if ($this->unitedStatesOnly) { $stateDiv->insert('<div class="jFormComponentSublabel"><p>State</p></div>'); } else { $stateDiv->insert('<div class="jFormComponentSublabel"><p>State / Province / Region</p></div>'); } if ($this->unitedStatesOnly) { $zipDiv->insert('<div class="jFormComponentSublabel"><p>Zip Code</p></div>'); } else { $zipDiv->insert('<div class="jFormComponentSublabel"><p>Postal / Zip Code</p></div>'); } $countryDiv->insert('<div class="jFormComponentSublabel"><p>Country</p></div>'); } // United States only switch if ($this->unitedStatesOnly) { $countryDiv->setAttribute('style', 'display: none;'); } // Hide address line 2 if ($this->addressLine2Hidden) { $addressLine2Div->setAttribute('style', 'display: none;'); } // Insert the address components $componentDiv->insert($addressLine1Div); $componentDiv->insert($addressLine2Div); $componentDiv->insert($cityDiv); $componentDiv->insert($stateDiv); $componentDiv->insert($zipDiv); $componentDiv->insert($countryDiv); // Add any description (optional) $componentDiv = $this->insertComponentDescription($componentDiv); // Add a tip (optional) $componentDiv = $this->insertComponentTip($componentDiv); return $componentDiv->__toString(); }