r97835 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97834‎ | r97835 | r97836 >
Date:18:55, 22 September 2011
Author:pgehres
Status:ok
Tags:fundraising 
Comment:
Begining to modularize form validation. Adding the ability to escape error tokens in RapidHTML. FU to r97776 and r97832
Modified paths:
  • /trunk/extensions/DonationInterface/payflowpro_gateway/forms/RapidHtml.php (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/validate_input.js (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/payflowpro_gateway/validate_input.js
@@ -39,6 +39,67 @@
4040 document.getElementById('payflowpro_gateway-form-submit-paypal').style.display = 'none';
4141 }
4242
 43+/*
 44+ * Validates the personal information fields
 45+ *
 46+ * @input form The form containing the inputs to be checked
 47+ *
 48+ * @return boolean true if no errors, false otherwise (also uses an alert() to notify the user)
 49+ */
 50+function validate_personal( form ){
 51+
 52+ // TODO: this form should only report a single error for the email address?
 53+
 54+ var output = '';
 55+ var currField = '';
 56+ var i = 0;
 57+ var msg = [ 'EmailAdd', 'Fname', 'Lname', 'Street', 'City', 'Zip'];
 58+ var fields = [ "emailAdd","fname","lname","street","city","zip" ],
 59+ numFields = fields.length;
 60+ for( i = 0; i < numFields; i++ ) {
 61+ if( document.getElementById( fields[i] ).value == '' ) {
 62+ currField = window['payflowproGatewayErrorMsg'+ msg[i]];
 63+ output += payflowproGatewayErrorMsgJs + ' ' + currField + '.\r\n';
 64+ }
 65+ }
 66+ var stateField = document.getElementById( 'state' );
 67+ var countryField = document.getElementById( 'country' );
 68+ if( stateField.options[stateField.selectedIndex].value == 'YY' ) {
 69+ output += payflowproGatewayErrorMsgJs + ' ' + window['payflowproGatewayErrorMsgState'] + '.\r\n';
 70+ }
 71+
 72+ if( countryField.type == "select" ){ // country is a dropdown select
 73+ if( countryField.options[countryField.selectedIndex].value == '' ) {
 74+ output += payflowproGatewayErrorMsgJs + ' ' + window['payflowproGatewayErrorMsgCountry'] + '.\r\n';
 75+ }
 76+ }
 77+ else{ // country is a hidden or text input
 78+ if( countryField.value == '' ) {
 79+ output += payflowproGatewayErrorMsgJs + ' ' + window['payflowproGatewayErrorMsgCountry'] + '.\r\n';
 80+ }
 81+ }
 82+
 83+ //set state to "outside us"
 84+ if ( form.country.value != 'US' ) {
 85+ form.state.value = 'XX';
 86+ }
 87+
 88+ // validate email address
 89+ var apos = form.emailAdd.value.indexOf("@");
 90+ var dotpos = form.emailAdd.value.lastIndexOf(".");
 91+
 92+ if( apos < 1 || dotpos-apos < 2 ) {
 93+ output += payflowproGatewayErrorMsgEmail;
 94+ }
 95+
 96+ if( output ) {
 97+ alert( output );
 98+ return false;
 99+ }
 100+
 101+ return true;
 102+}
 103+
43104 function validate_form( form ) {
44105 if( form == null ){
45106 form = document.payment
Index: trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php
@@ -79,6 +79,7 @@
8080 $wgOut->addScript( Skin::makeVariablesScript( $scriptVars ) );
8181
8282 // @fixme can this be moved into the form generators?
 83+ // @fixme this is broken on MW 1.16, executes before jQuery load
8384 $js = <<<EOT
8485 <script type="text/javascript">
8586 jQuery(document).ready(function() {
Index: trunk/extensions/DonationInterface/payflowpro_gateway/forms/RapidHtml.php
@@ -39,7 +39,7 @@
4040 '@utm_source', // => self::getUtmSource(),
4141 '@utm_medium', // => $wgRequest->getText( 'utm_medium' ),
4242 '@utm_campaign', // => $wgRequest->getText( 'utm_campaign' ),
43 - // try to honr the user-set language (uselang), otherwise the language set in the URL (language)
 43+ // try to honor the user-set language (uselang), otherwise the language set in the URL (language)
4444 '@language', // => $wgRequest->getText( 'uselang', $wgRequest->getText( 'language' ) ),
4545 '@comment-option', // => $wgRequest->getText( 'comment-option' ),
4646 '@comment', // => $wgRequest->getText( 'comment' ),
@@ -147,9 +147,21 @@
148148 $form = str_replace( $token, $replace, $form );
149149 }
150150
151 - // replace errors
152 - $form = str_replace( $this->error_tokens, $this->form_errors, $form );
 151+ // @fixme why do some errors have HTML in them
 152+ // replace errors|escape with escaped versions
 153+ $escape_error_tokens = array();
 154+ foreach ( $this->error_tokens as $token ) {
 155+ $escape_error_tokens[] = "$token|escape";
 156+ }
 157+ $escape_errors = array();
 158+ foreach ( $this->form_errors as $error ) {
 159+ $escape_errors[] = addslashes($error);
 160+ }
 161+ $form = str_replace($escape_error_tokens, $escape_errors, $form);
153162
 163+ // replace standard errors
 164+ $form = str_replace($this->error_tokens, $this->form_errors, $form);
 165+
154166 // handle captcha
155167 $form = str_replace( "@captcha", $this->getCaptchaHtml(), $form );
156168

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r97776Adding webitects form for this week as well as a few changes to RapidHTMLpgehres01:10, 22 September 2011
r97832Self-revert, accidental tabs->spacespgehres18:09, 22 September 2011

Status & tagging log