r101874 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101873‎ | r101874 | r101875 >
Date:20:26, 3 November 2011
Author:jpostlethwaite
Status:ok
Tags:fundraising 
Comment:
Amount radio buttons are now prepopulated when necessary. Hidden amount field is also prepopulated.
Modified paths:
  • /trunk/extensions/DonationInterface/gateway_forms/Form.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/gateway_forms/Form.php
@@ -416,27 +416,36 @@
417417 $displayCurrencyDropdown = isset( $displayCurrencyDropdown ) ? (boolean) $displayCurrencyDropdown : true;
418418 $setCurrency = isset( $setCurrency ) ? (string) $setCurrency : '';
419419 $displayCurrencyDropdown = empty( $setCurrency ) ? $displayCurrencyDropdown : false;
 420+
 421+ $amount = isset( $this->form_data['amount'] ) ? (string) $this->form_data['amount'] : '0';
 422+
 423+ // Treat values as string for comparison
 424+ $amountValues = array('5', '10', '20', '35', '50', '100', '250',);
420425
 426+ $isOther = in_array( $amount, $amountValues) ? false : true;
 427+ $amountOther = $isOther ? $amount : '';
 428+
 429+ $checked = 'checked="checked" ';
421430 // The text to return
422431 $return = '';
423432
424433 $return .= '<table id="amount-radio">';
425434 $return .= ' <tr>';
426 - $return .= ' <td><label><input type="radio" name="amountRadio" value="5" /> 5</label></td>';
427 - $return .= ' <td><label><input type="radio" name="amountRadio" value="10" /> 10</label></td>';
428 - $return .= ' <td><label><input type="radio" name="amountRadio" value="20" /> 20</label></td>';
429 - $return .= ' <td><label><input type="radio" name="amountRadio" value="35" /> 35</label></td>';
 435+ $return .= ' <td><label><input type="radio" name="amountRadio" value="5" ' . ( $amount == '5' ? $checked : '' ) . '/> 5</label></td>';
 436+ $return .= ' <td><label><input type="radio" name="amountRadio" value="10" ' . ( $amount == '10' ? $checked : '' ) . '/> 10</label></td>';
 437+ $return .= ' <td><label><input type="radio" name="amountRadio" value="20" ' . ( $amount == '20' ? $checked : '' ) . '/> 20</label></td>';
 438+ $return .= ' <td><label><input type="radio" name="amountRadio" value="35" ' . ( $amount == '35' ? $checked : '' ) . '/> 35</label></td>';
430439 $return .= ' </tr>';
431440 $return .= ' <tr>';
432 - $return .= ' <td><label><input type="radio" name="amountRadio" value="50" /> 50</label></td>';
433 - $return .= ' <td><label><input type="radio" name="amountRadio" value="100" /> 100</label></td>';
434 - $return .= ' <td><label><input type="radio" name="amountRadio" value="250" /> 250</label></td>';
 441+ $return .= ' <td><label><input type="radio" name="amountRadio" value="50" ' . ( $amount == '50' ? $checked : '' ) . '/> 50</label></td>';
 442+ $return .= ' <td><label><input type="radio" name="amountRadio" value="100" ' . ( $amount == '100' ? $checked : '' ) . '/> 100</label></td>';
 443+ $return .= ' <td><label><input type="radio" name="amountRadio" value="250" ' . ( $amount == '250' ? $checked : '' ) . '/> 250</label></td>';
435444 $return .= ' <td>';
436 - $return .= ' <input type="radio" name="amountRadio" id="input_amount_other" value="other" />';
437 - $return .= ' <label><input type="text" class="txt-sm hint" name="amountGiven" size="4" id="other-amount" title="Other..." onfocus=""/></label>';
 445+ $return .= ' <input type="radio" name="amountRadio" id="input_amount_other" value="other" ' . ( $isOther ? $checked : '' ) . ' />';
 446+ $return .= ' <label><input type="text" class="txt-sm hint" name="amountGiven" size="4" id="other-amount" title="Other..." onfocus="" value="' . $amountOther . '" /></label>';
438447
439448 // Add hidden amount field for validation
440 - $return .= Html::hidden( 'amount', 0 );
 449+ $return .= Html::hidden( 'amount', $amount );
441450
442451 // Set currency
443452 if ( !empty( $setCurrency ) ) {

Status & tagging log