Index: trunk/extensions/DonationInterface/globalcollect_gateway/forms/TwoStepAmount.php |
— | — | @@ -23,103 +23,48 @@ |
24 | 24 | */ |
25 | 25 | class Gateway_Form_TwoStepAmount extends Gateway_Form { |
26 | 26 | |
27 | | - public function __construct( &$gateway, &$form_errors ) { |
28 | | - parent::__construct( $gateway, $form_errors ); |
| 27 | + /** |
| 28 | + * Initialize the form |
| 29 | + * |
| 30 | + */ |
| 31 | + protected function init() { |
29 | 32 | |
30 | 33 | //TODO: This is pretty odd to do here. However, as this form is only |
31 | 34 | //being used for testing purposes, it's getting the update that goes |
32 | 35 | //along with yet another change in Form Class construction. |
33 | 36 | $this->form_data['payment_method'] = empty($this->form_data['payment_method']) ? 'bt' : $this->form_data['payment_method']; |
34 | 37 | $this->form_data['payment_submethod'] = empty($this->form_data['payment_submethod']) ? 'bt' : $this->form_data['payment_submethod']; |
35 | | - |
36 | | - //$this->form_data['payment_method'] = 'rtbt'; |
37 | | - //$this->form_data['payment_submethod'] = 'rtbt_nordea_sweeden'; |
38 | | - |
39 | | - //$this->form_data['payment_method'] = 'rtbt'; |
40 | | - //$this->form_data['payment_submethod'] = 'rtbt_ideal'; |
41 | | - //$this->form_data['issuerids'] = array(); |
42 | 38 | |
| 39 | + $this->setPaymentMethod( $this->form_data['payment_method'] ); |
| 40 | + $this->setPaymentSubmethod( $this->form_data['payment_submethod'] ); |
| 41 | + |
43 | 42 | $this->form_data['process'] = 'other'; |
44 | 43 | |
45 | | - // we only want to load this JS if the form is being rendered |
46 | | - $this->loadValidateJs(); // validation JS |
47 | | - |
48 | | - $this->loadPlaceholders(); |
| 44 | + $this->loadResources(); |
49 | 45 | } |
50 | 46 | |
51 | | - public function loadPlaceholders() { |
52 | | - global $wgOut; |
53 | | - // form placeholder values |
54 | | - $first = wfMsg( 'donate_interface-donor-fname' ); |
55 | | - $last = wfMsg( 'donate_interface-donor-lname' ); |
56 | | - $js = <<<EOT |
57 | | -<script type="text/javascript"> |
58 | | -function loadPlaceholders() { |
59 | | - var fname = document.getElementById('fname'); |
60 | | - var lname = document.getElementById('lname'); |
61 | | - var amountOther = document.getElementById('amountOther'); |
62 | | - if (fname.value == '') { |
63 | | - fname.style.color = '#999999'; |
64 | | - fname.value = '$first'; |
| 47 | + /** |
| 48 | + * Load form resources |
| 49 | + */ |
| 50 | + protected function loadResources() { |
| 51 | + |
| 52 | + $this->loadValidateJs(); |
65 | 53 | } |
66 | | - if (lname.value == '') { |
67 | | - lname.style.color = '#999999'; |
68 | | - lname.value = '$last'; |
69 | | - } |
70 | | -} |
71 | | -addEvent( window, 'load', loadPlaceholders ); |
72 | 54 | |
73 | | -function formCheck( ccform ) { |
74 | | - var msg = [ 'EmailAdd', 'Fname', 'Lname', 'Street', 'City', 'Zip' ]; |
75 | | - |
76 | | - var fields = ["emailAdd","fname","lname","street","city","zip" ], |
77 | | - numFields = fields.length, |
78 | | - i, |
79 | | - output = '', |
80 | | - currField = ''; |
81 | | - |
82 | | - for( i = 0; i < numFields; i++ ) { |
83 | | - if( document.getElementById( fields[i] ).value == '' ) { |
84 | | - currField = window['payflowproGatewayErrorMsg'+ msg[i]]; |
85 | | - output += payflowproGatewayErrorMsgJs + ' ' + currField + '.\\r\\n'; |
86 | | - } |
87 | | - } |
88 | | - |
89 | | - if (document.getElementById('fname').value == '$first') { |
90 | | - output += payflowproGatewayErrorMsgJs + ' first name.\\r\\n'; |
91 | | - } |
92 | | - if (document.getElementById('lname').value == '$last') { |
93 | | - output += payflowproGatewayErrorMsgJs + ' last name.\\r\\n'; |
94 | | - } |
95 | | - var countryField = document.getElementById( 'country' ); |
96 | | - if( countryField.options[countryField.selectedIndex].value == '' ) { |
97 | | - output += payflowproGatewayErrorMsgJs + ' ' + window['payflowproGatewayErrorMsgCountry'] + '.\\r\\n'; |
98 | | - } |
99 | | - |
100 | | - // validate email address |
101 | | - var apos = document.payment.emailAdd.value.indexOf("@"); |
102 | | - var dotpos = document.payment.emailAdd.value.lastIndexOf("."); |
103 | | - |
104 | | - if( apos < 1 || dotpos-apos < 2 ) { |
105 | | - output += payflowproGatewayErrorMsgEmail; |
106 | | - } |
107 | | - |
108 | | - if( output ) { |
109 | | - alert( output ); |
110 | | - return false; |
111 | | - } else { |
112 | | - return true; |
113 | | - } |
114 | | -} |
115 | | -</script> |
116 | | -EOT; |
| 55 | + protected function loadValidateJs() { |
| 56 | + global $wgOut; |
| 57 | + $wgOut->addModules( 'gc.form.core.validate' ); |
| 58 | + $wgOut->addHeadItem( 'donationinterface_validate', "\n" . '<script type="text/javascript" src="/extensions/DonationInterface/globalcollect_gateway/modules/js/validate.js"></script>' ); |
| 59 | + $wgOut->addHeadItem( 'donationinterface_js_validate', "\n" . '<script type="text/javascript" src="/extensions/DonationInterface/globalcollect_gateway/modules/js/jquery.validate.js"></script>' ); |
| 60 | + $wgOut->addHeadItem( 'donationinterface_js_validate_additional', "\n" . '<script type="text/javascript" src="/extensions/DonationInterface/globalcollect_gateway/modules/js/jquery.validate.additional-methods.js"></script>' ); |
| 61 | + |
| 62 | + $js = "\n" . '<script type="text/javascript">' . "validateForm( { validate: { address: true, amount: true, creditCard: false, email: true, name: true, }, payment_method: '" . $this->getPaymentMethod() . "', payment_submethod: '" . $this->getPaymentSubmethod() . "', formId: '" . $this->getFormId() . "' } );" . '</script>' . "\n"; |
117 | 63 | $wgOut->addHeadItem( 'placeholders', $js ); |
118 | 64 | } |
119 | 65 | |
120 | 66 | /** |
121 | | - * Required method for constructing the entire form |
| 67 | + * Required method for returning the full HTML for a form. |
122 | 68 | * |
123 | | - * This can of course be overloaded by a child class. |
124 | 69 | * @return string The entire form HTML |
125 | 70 | */ |
126 | 71 | public function getForm() { |
— | — | @@ -129,14 +74,20 @@ |
130 | 75 | return $form; |
131 | 76 | } |
132 | 77 | |
| 78 | + /** |
| 79 | + * Generate the first part of the form |
| 80 | + */ |
133 | 81 | public function generateFormStart() { |
134 | | - $form = $this->generateBannerHeader(); |
| 82 | + |
| 83 | + $form = ''; |
| 84 | + |
| 85 | + //$form .= $this->generateBannerHeader(); |
135 | 86 | |
136 | 87 | $form .= Xml::openElement( 'div', array( 'id' => 'mw-creditcard' ) ); |
137 | 88 | |
138 | 89 | // provide a place at the top of the form for displaying general messages |
139 | 90 | if ( $this->form_errors['general'] ) { |
140 | | - $form .= Xml::openElement( 'div', array( 'id' => 'mw-payflow-general-error' ) ); |
| 91 | + $form .= Xml::openElement( 'div', array( 'id' => 'mw-payment-general-error' ) ); |
141 | 92 | if ( is_array( $this->form_errors['general'] ) ) { |
142 | 93 | foreach ( $this->form_errors['general'] as $this->form_errors_msg ) { |
143 | 94 | $form .= Xml::tags( 'p', array( 'class' => 'creditcard-error-msg' ), $this->form_errors_msg ); |
— | — | @@ -155,30 +106,26 @@ |
156 | 107 | |
157 | 108 | // Xml::element seems to convert html to htmlentities |
158 | 109 | $form .= "<p class='creditcard-error-msg'>" . $this->form_errors['retryMsg'] . "</p>"; |
159 | | - $form .= Xml::openElement( 'form', array( 'name' => 'payment', 'method' => 'post', 'action' => $this->getNoCacheAction(), 'onsubmit' => 'return formCheck(this)', 'autocomplete' => 'off' ) ); |
| 110 | + $form .= Xml::openElement( 'form', array( 'id' => $this->getFormId(), 'name' => $this->getFormName(), 'method' => 'post', 'action' => $this->getNoCacheAction(), 'onsubmit' => '', 'autocomplete' => 'off' ) ); |
160 | 111 | |
161 | | - $form .= Xml::openElement( 'div', array( 'id' => 'left-column', 'class' => 'payflow-cc-form-section' ) ); |
| 112 | + $form .= Xml::openElement( 'div', array( 'id' => 'left-column', 'class' => 'payment-cc-form-section' ) ); |
162 | 113 | $form .= $this->generatePersonalContainer(); |
163 | 114 | $form .= $this->generatePaymentContainer(); |
164 | 115 | $form .= $this->generateFormSubmit(); |
165 | 116 | $form .= Xml::closeElement( 'div' ); // close div#left-column |
166 | 117 | |
167 | | - //$form .= Xml::openElement( 'div', array( 'id' => 'right-column', 'class' => 'payflow-cc-form-section' ) ); |
| 118 | + //$form .= Xml::openElement( 'div', array( 'id' => 'right-column', 'class' => 'payment-cc-form-section' ) ); |
168 | 119 | |
169 | 120 | return $form; |
170 | 121 | } |
171 | 122 | |
172 | 123 | public function generateFormSubmit() { |
173 | 124 | // submit button |
174 | | - $form = Xml::openElement( 'div', array( 'id' => 'payflowpro_gateway-form-submit' ) ); |
| 125 | + $form = Xml::openElement( 'div', array( 'id' => 'payment_gateway-form-submit' ) ); |
175 | 126 | $form .= Xml::openElement( 'div', array( 'id' => 'mw-donate-submit-button' ) ); |
176 | | - // $form .= Xml::submitButton( wfMsg( 'donate_interface-submit-button' )); |
177 | | - $form .= Xml::element( 'input', array( 'class' => 'button-plain', 'value' => wfMsg( 'donate_interface-cc-button' ), 'type' => 'submit' ) ); |
| 127 | + $form .= Xml::element( 'input', array( 'class' => 'button-plain', 'value' => wfMsg( 'donate_interface-submit-button' ), 'type' => 'submit' ) ); |
178 | 128 | $form .= Xml::closeElement( 'div' ); // close div#mw-donate-submit-button |
179 | | - $form .= Xml::openElement( 'div', array( 'class' => 'mw-donate-submessage', 'id' => 'payflowpro_gateway-donate-submessage' ) ) . |
180 | | - wfMsg( 'donate_interface-donate-click' ); |
181 | | - $form .= Xml::closeElement( 'div' ); // close div#payflowpro_gateway-donate-submessage |
182 | | - $form .= Xml::closeElement( 'div' ); // close div#payflowpro_gateway-form-submit |
| 129 | + $form .= Xml::closeElement( 'div' ); // close div#payment_gateway-form-submit |
183 | 130 | return $form; |
184 | 131 | } |
185 | 132 | |
— | — | @@ -190,9 +137,6 @@ |
191 | 138 | $form .= Html::hidden( $field, $value ); |
192 | 139 | } |
193 | 140 | |
194 | | - $value = 'BANK_TRANSFER'; |
195 | | - //$form .= Html::hidden( $field, $value ); |
196 | | - //$form .= Xml::closeElement( 'div' ); // close div#right-column |
197 | 141 | $form .= Xml::closeElement( 'form' ); |
198 | 142 | $form .= Xml::closeElement( 'div' ); // close div#mw-creditcard-form |
199 | 143 | $form .= $this->generateDonationFooter(); |
— | — | @@ -202,14 +146,14 @@ |
203 | 147 | |
204 | 148 | protected function generatePersonalContainer() { |
205 | 149 | $form = ''; |
206 | | - $form .= Xml::openElement( 'div', array( 'id' => 'payflowpro_gateway-personal-info' ) ); ; |
207 | | - //$form .= Xml::tags( 'h3', array( 'class' => 'payflow-cc-form-header', 'id' => 'payflow-cc-form-header-personal' ), wfMsg( 'donate_interface-cc-form-header-personal' ) ); |
208 | | - $form .= Xml::openElement( 'table', array( 'id' => 'payflow-table-donor' ) ); |
| 150 | + $form .= Xml::openElement( 'div', array( 'id' => 'payment_gateway-personal-info' ) ); ; |
| 151 | + //$form .= Xml::tags( 'h3', array( 'class' => 'payment-cc-form-header', 'id' => 'payment-cc-form-header-personal' ), wfMsg( 'donate_interface-cc-form-header-personal' ) ); |
| 152 | + $form .= Xml::openElement( 'table', array( 'id' => 'payment-table-donor' ) ); |
209 | 153 | |
210 | 154 | $form .= $this->generatePersonalFields(); |
211 | 155 | |
212 | | - $form .= Xml::closeElement( 'table' ); // close table#payflow-table-donor |
213 | | - $form .= Xml::closeElement( 'div' ); // close div#payflowpro_gateway-personal-info |
| 156 | + $form .= Xml::closeElement( 'table' ); // close table#payment-table-donor |
| 157 | + $form .= Xml::closeElement( 'div' ); // close div#payment_gateway-personal-info |
214 | 158 | |
215 | 159 | return $form; |
216 | 160 | } |
— | — | @@ -243,14 +187,14 @@ |
244 | 188 | protected function generatePaymentContainer() { |
245 | 189 | $form = ''; |
246 | 190 | // credit card info |
247 | | - $form .= Xml::openElement( 'div', array( 'id' => 'payflowpro_gateway-payment-info' ) ); |
248 | | - //$form .= Xml::tags( 'h3', array( 'class' => 'payflow-cc-form-header', 'id' => 'payflow-cc-form-header-payment' ), wfMsg( 'donate_interface-cc-form-header-payment' ) ); |
249 | | - $form .= Xml::openElement( 'table', array( 'id' => 'payflow-table-cc' ) ); |
| 191 | + $form .= Xml::openElement( 'div', array( 'id' => 'donation-payment-info' ) ); |
| 192 | + //$form .= Xml::tags( 'h3', array( 'class' => 'payment-cc-form-header', 'id' => 'payment-cc-form-header-payment' ), wfMsg( 'donate_interface-cc-form-header-payment' ) ); |
| 193 | + $form .= Xml::openElement( 'table', array( 'id' => 'donation-table-cc' ) ); |
250 | 194 | |
251 | 195 | $form .= $this->generatePaymentFields(); |
252 | 196 | |
253 | | - $form .= Xml::closeElement( 'table' ); // close table#payflow-table-cc |
254 | | - $form .= Xml::closeElement( 'div' ); // close div#payflowpro_gateway-payment-info |
| 197 | + $form .= Xml::closeElement( 'table' ); // close table#payment-table-cc |
| 198 | + $form .= Xml::closeElement( 'div' ); // close div#payment_gateway-payment-info |
255 | 199 | |
256 | 200 | return $form; |
257 | 201 | } |
— | — | @@ -258,12 +202,12 @@ |
259 | 203 | protected function generatePaymentFields() { |
260 | 204 | // amount |
261 | 205 | $form = '<tr>'; |
262 | | - $form .= '<td colspan="2"><span class="creditcard-error-msg">' . $this->form_errors['invalidamount'] . '</span></td>'; |
| 206 | + $form .= '<td colspan="2"><span class="donation-error-msg">' . $this->form_errors['invalidamount'] . '</span></td>'; |
263 | 207 | $form .= '</tr>'; |
264 | 208 | $form .= '<tr>'; |
265 | 209 | $form .= '<td class="label">' . Xml::label( wfMsg( 'donate_interface-donor-amount' ), 'amount' ) . '</td>'; |
266 | | - $form .= '<td>' . Xml::input( 'amount', '7', $this->form_data['amount'], array( 'type' => 'text', 'maxlength' => '10', 'id' => 'amount' ) ) . |
267 | | - ' ' . $this->generateCurrencyDropdown() . '</td>'; |
| 210 | + $form .= '<td>' . Xml::input( 'amount', '7', $this->form_data['amount'], array( 'class' => 'required', 'type' => 'text', 'maxlength' => '10', 'id' => 'amount' ) ) . |
| 211 | + ' ' . $this->generateCurrencyDropdown( array( 'showCardsOnCurrencyChange' => false, ) ) . '</td>'; |
268 | 212 | $form .= '</tr>'; |
269 | 213 | |
270 | 214 | return $form; |