r98915 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98914‎ | r98915 | r98916 >
Date:20:58, 4 October 2011
Author:jpostlethwaite
Status:ok
Tags:
Comment:
Removed GatewayForm::fnValidateForm(). GatewayForm::validateForm() is now the preferred method to validate forms.
Modified paths:
  • /branches/fundraising/extensions/DonationInterface/gateway_common/GatewayForm.php (modified) (history)

Diff [purge]

Index: branches/fundraising/extensions/DonationInterface/gateway_common/GatewayForm.php
@@ -48,79 +48,6 @@
4949
5050 /**
5151 * Checks posted form data for errors and returns array of messages
52 - */
53 - protected function fnValidateForm( &$data, &$error ) {
54 - // begin with no errors
55 - $error_result = '0';
56 -
57 - // create the human-speak message for required fields
58 - // does not include fields that are not required
59 - $gateway_identifier = $this->adapter->getIdentifier();
60 - $msg = array(
61 - 'amount' => wfMsg( $gateway_identifier . '_gateway-error-msg-amount' ),
62 - 'emailAdd' => wfMsg( $gateway_identifier . '_gateway-error-msg-emailAdd' ),
63 - 'fname' => wfMsg( $gateway_identifier . '_gateway-error-msg-fname' ),
64 - 'lname' => wfMsg( $gateway_identifier . '_gateway-error-msg-lname' ),
65 - 'street' => wfMsg( $gateway_identifier . '_gateway-error-msg-street' ),
66 - 'city' => wfMsg( $gateway_identifier . '_gateway-error-msg-city' ),
67 - 'state' => wfMsg( $gateway_identifier . '_gateway-error-msg-state' ),
68 - 'zip' => wfMsg( $gateway_identifier . '_gateway-error-msg-zip' ),
69 - 'card_num' => wfMsg( $gateway_identifier . '_gateway-error-msg-card_num' ),
70 - 'expiration' => wfMsg( $gateway_identifier . '_gateway-error-msg-expiration' ),
71 - 'cvv' => wfMsg( $gateway_identifier . '_gateway-error-msg-cvv' ),
72 - );
73 -
74 - // find all empty fields and create message
75 - foreach ( $data as $key => $value ) {
76 - if ( $value == '' || ($key == 'state' && $value == 'YY' ) ) {
77 - // ignore fields that are not required
78 - if ( isset( $msg[$key] ) ) {
79 - $error[$key] = "**" . wfMsg( $gateway_identifier . '_gateway-error-msg', $msg[$key] ) . "**<br />";
80 - $error_result = '1';
81 - }
82 - }
83 - }
84 -
85 - // check amount
86 - $priceFloor = $this->adapter->getGlobal( 'PriceFloor' );
87 - $priceCeiling = $this->adapter->getGlobal( 'PriceCeiling' );
88 - if ( !preg_match( '/^\d+(\.(\d+)?)?$/', $data['amount'] ) ||
89 - ( ( float ) $this->convert_to_usd( $data['currency'], $data['amount'] ) < ( float ) $priceFloor ||
90 - ( float ) $this->convert_to_usd( $data['currency'], $data['amount'] ) > ( float ) $priceCeiling ) ) {
91 - $error['invalidamount'] = wfMsg( $gateway_identifier . '_gateway-error-msg-invalid-amount' );
92 - $error_result = '1';
93 - }
94 -
95 - // is email address valid?
96 - $isEmail = User::isValidEmailAddr( $data['email'] );
97 -
98 - // create error message (supercedes empty field message)
99 - if ( !$isEmail ) {
100 - $error['emailAdd'] = wfMsg( $gateway_identifier . '_gateway-error-msg-email' );
101 - $error_result = '1';
102 - }
103 -
104 - // validate that credit card number entered is correct and set the card type
105 - if ( preg_match( '/^3[47][0-9]{13}$/', $data['card_num'] ) ) { // american express
106 - $data['card'] = 'american';
107 - } elseif ( preg_match( '/^5[1-5][0-9]{14}$/', $data['card_num'] ) ) { // mastercard
108 - $data['card'] = 'mastercard';
109 - } elseif ( preg_match( '/^4[0-9]{12}(?:[0-9]{3})?$/', $data['card_num'] ) ) {// visa
110 - $data['card'] = 'visa';
111 - } elseif ( preg_match( '/^6(?:011|5[0-9]{2})[0-9]{12}$/', $data['card_num'] ) ) { // discover
112 - $data['card'] = 'discover';
113 - } else { // an invalid credit card number was entered
114 - //TODO: Make sure this is uncommented when you commit for reals!
115 - //$error_result = '1';
116 - //$error[ 'card_num' ] = wfMsg( $gateway_identifier . '_gateway-error-msg-card-num' );
117 - }
118 -
119 - $this->adapter->setValidationErrors( $error );
120 - return $error_result;
121 - }
122 -
123 - /**
124 - * Checks posted form data for errors and returns array of messages
12552 *
12653 * This is update to GatewayForm::fnValidateForm().
12754 *

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r98476Added GatewayForm::validateForm() so certain elements can be validated. The o...jpostlethwaite22:19, 29 September 2011

Status & tagging log