r96078 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96077‎ | r96078 | r96079 >
Date:01:26, 2 September 2011
Author:kaldari
Status:ok (Comments)
Tags:
Comment:
adding missing form validation functions
Modified paths:
  • /trunk/extensions/DonationInterface/payflowpro_gateway/forms/html/globalcollect_test.html (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/forms/html/globalcollect_test_2.html (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/payflowpro_gateway/forms/html/globalcollect_test.html
@@ -5,6 +5,60 @@
66 .step2hidden{ display:none; }
77 #footer-places { display:none; }
88 </style>
 9+
 10+<script type="text/javascript">
 11+function formCheck( ccform ) {
 12+ var msg = [ 'EmailAdd', 'Fname', 'Lname', 'Street', 'City', 'Zip' ];
 13+
 14+ var fields = ["emailAdd","fname","lname","street","city","zip" ],
 15+ numFields = fields.length,
 16+ i,
 17+ output = '',
 18+ currField = '';
 19+
 20+ for( i = 0; i < numFields; i++ ) {
 21+ if( document.getElementById( fields[i] ).value == '' ) {
 22+ currField = window['payflowproGatewayErrorMsg'+ msg[i]];
 23+ output += payflowproGatewayErrorMsgJs + ' ' + currField + '.\r\n';
 24+ }
 25+ }
 26+
 27+ if (document.getElementById('fname').value == '$first') {
 28+ output += payflowproGatewayErrorMsgJs + ' first name.\r\n';
 29+ }
 30+ if (document.getElementById('lname').value == '$last') {
 31+ output += payflowproGatewayErrorMsgJs + ' last name.\r\n';
 32+ }
 33+ if (document.getElementById('street').value == '$street') {
 34+ output += payflowproGatewayErrorMsgJs + ' street address.\r\n';
 35+ }
 36+ if (document.getElementById('city').value == '$city') {
 37+ output += payflowproGatewayErrorMsgJs + ' city.\r\n';
 38+ }
 39+ if (document.getElementById('zip').value == '$zip') {
 40+ output += payflowproGatewayErrorMsgJs + ' zip code.\r\n';
 41+ }
 42+
 43+ var stateField = document.getElementById( 'state' );
 44+ if( stateField.options[stateField.selectedIndex].value == '' ) {
 45+ output += payflowproGatewayErrorMsgJs + ' ' + window['payflowproGatewayErrorMsgState'] + '.\r\n';
 46+ }
 47+
 48+ // validate email address
 49+ var apos = document.payment.emailAdd.value.indexOf("@");
 50+ var dotpos = document.payment.emailAdd.value.lastIndexOf(".");
 51+
 52+ if( apos < 1 || dotpos-apos < 2 ) {
 53+ output += payflowproGatewayErrorMsgEmail;
 54+ }
 55+
 56+ if( output ) {
 57+ alert( output );
 58+ return false;
 59+ }
 60+}
 61+</script>
 62+
963 <table width="100%" cellspacing="0" cellpadding="0" border="0">
1064 <tr>
1165 <td id="appeal" valign="top">
@@ -61,9 +115,6 @@
62116 <td colspan="2"><span class="creditcard-error-msg">#card#card_num</span></td>
63117 </tr>
64118 <tr>
65 - <td colspan="2"><span class="creditcard-error-msg">#card</span></td>
66 - </tr>
67 - <tr>
68119 <td colspan="2">
69120 <table cellspacing="0" cellpadding="4" border="1" id="donation_amount">
70121 <tr>
Index: trunk/extensions/DonationInterface/payflowpro_gateway/forms/html/globalcollect_test_2.html
@@ -29,6 +29,57 @@
3030 if($(this).attr("placeholder") == $(this).val()) {$(this).val('');}
3131 });
3232 });
 33+
 34+function formCheck( ccform ) {
 35+ var msg = [ 'EmailAdd', 'Fname', 'Lname', 'Street', 'City', 'Zip' ];
 36+
 37+ var fields = ["emailAdd","fname","lname","street","city","zip" ],
 38+ numFields = fields.length,
 39+ i,
 40+ output = '',
 41+ currField = '';
 42+
 43+ for( i = 0; i < numFields; i++ ) {
 44+ if( document.getElementById( fields[i] ).value == '' ) {
 45+ currField = window['payflowproGatewayErrorMsg'+ msg[i]];
 46+ output += payflowproGatewayErrorMsgJs + ' ' + currField + '.\r\n';
 47+ }
 48+ }
 49+
 50+ if (document.getElementById('fname').value == '$first') {
 51+ output += payflowproGatewayErrorMsgJs + ' first name.\r\n';
 52+ }
 53+ if (document.getElementById('lname').value == '$last') {
 54+ output += payflowproGatewayErrorMsgJs + ' last name.\r\n';
 55+ }
 56+ if (document.getElementById('street').value == '$street') {
 57+ output += payflowproGatewayErrorMsgJs + ' street address.\r\n';
 58+ }
 59+ if (document.getElementById('city').value == '$city') {
 60+ output += payflowproGatewayErrorMsgJs + ' city.\r\n';
 61+ }
 62+ if (document.getElementById('zip').value == '$zip') {
 63+ output += payflowproGatewayErrorMsgJs + ' zip code.\r\n';
 64+ }
 65+
 66+ var stateField = document.getElementById( 'state' );
 67+ if( stateField.options[stateField.selectedIndex].value == '' ) {
 68+ output += payflowproGatewayErrorMsgJs + ' ' + window['payflowproGatewayErrorMsgState'] + '.\r\n';
 69+ }
 70+
 71+ // validate email address
 72+ var apos = document.payment.emailAdd.value.indexOf("@");
 73+ var dotpos = document.payment.emailAdd.value.lastIndexOf(".");
 74+
 75+ if( apos < 1 || dotpos-apos < 2 ) {
 76+ output += payflowproGatewayErrorMsgEmail;
 77+ }
 78+
 79+ if( output ) {
 80+ alert( output );
 81+ return false;
 82+ }
 83+}
3384 </script>
3485
3586

Comments

#Comment by Awjrichards (talk | contribs)   15:46, 2 September 2011

This is fine for now, but it's a bummer to have to copy/paste the same functionality. We should think about how to clean this up in the future - if this is something we're going to need to use regularly in rapidHtml we should figure out how to keep this code in one place. Alternatively, whoever's working on the RapidHTML forms *should* have commit access to extensions - there's nothing stopping them from committing Javascript/CSS files.

Status & tagging log