CiviCRM

Unable to make donation from country which does not have state/province information

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed/Completed
  • Affects Version/s: 3.0.2
  • Fix Version/s: 3.2
  • Component/s: CiviContribute
  • Labels:
    None

Description

To reproducte:

 - In localisation settings, add all countries, and all states.
 - Go to a contribution page
 - Select Bermuda as the country
 - The state field is not populated for that country.
 - Try and submit the form
 - Validation error, because state/province is a required field.

So, either ALL countries must have complete state/province information (pretty much impossible).

Or, the state/province field should only be required for countries that have state/province information. This could be in the validation process process, and with a little javascript to remove the red asterix for completenes.

Or, if the dropdown can't be populated, a textfield should be shown instead.

Activity

Hide
Donald A. Lobo added a comment -

Tom:

how did u get around this?
Show
Donald A. Lobo added a comment - Tom: how did u get around this?
Hide
Tom Kirkpatrick added a comment -
Hi Donald. We haven't got round this yet. It's still an open issue our end.
Show
Tom Kirkpatrick added a comment - Hi Donald. We haven't got round this yet. It's still an open issue our end.
Hide
Tom Kirkpatrick added a comment -
We now have a fix for this in place. It goes a little like this, at the top of Main.php:formRule

        // If selected country has possible values for state/province mark the
        // state/province field as required.
        if ( CRM_Utils_Array::value( "billing_country_id-{$self->_bltID}", $fields ) ) {
          require_once 'CRM/Core/DAO/StateProvince.php';
          $state_province =& new CRM_Core_DAO_StateProvince();
          $state_province->country_id = $fields["billing_country_id-{$self->_bltID}"];
          
          if ( $state_province->count() > 0 ) {
          
              // check that the state/province data is not excluded by a
              // limitation in the localisation settings.
              require_once 'CRM/Core/PseudoConstant.php';
              $countryIsoCodes =& CRM_Core_PseudoConstant::countryIsoCode();
              $limitCodes = $config->provinceLimit( );
              $limitIds = array();
              foreach ($limitCodes as $code) {
                  $limitIds = array_merge($limitIds, array_keys($countryIsoCodes, $code));
              }
              
              if (in_array( $fields["billing_country_id-{$self->_bltID}"], $limitIds)) {
                  $self->_fields["billing_state_province_id-{$self->_bltID}"]['is_required'] = TRUE;
              }
          }
        }

Then, in CRM/Core/Payment/Form.php I removed the is_required attribute from the state/province field.

The only problem is that the red asterisk then disappears from the form element. I'm not much good with Smarty, so I just manually hacked the asterix into the template. But I guess it would be better to manipulate the smarty object and ensure that the template still thinks the field is required.
Show
Tom Kirkpatrick added a comment - We now have a fix for this in place. It goes a little like this, at the top of Main.php:formRule         // If selected country has possible values for state/province mark the         // state/province field as required.         if ( CRM_Utils_Array::value( "billing_country_id-{$self->_bltID}", $fields ) ) {           require_once 'CRM/Core/DAO/StateProvince.php';           $state_province =& new CRM_Core_DAO_StateProvince();           $state_province->country_id = $fields["billing_country_id-{$self->_bltID}"];                      if ( $state_province->count() > 0 ) {                          // check that the state/province data is not excluded by a               // limitation in the localisation settings.               require_once 'CRM/Core/PseudoConstant.php';               $countryIsoCodes =& CRM_Core_PseudoConstant::countryIsoCode();               $limitCodes = $config->provinceLimit( );               $limitIds = array();               foreach ($limitCodes as $code) {                   $limitIds = array_merge($limitIds, array_keys($countryIsoCodes, $code));               }                              if (in_array( $fields["billing_country_id-{$self->_bltID}"], $limitIds)) {                   $self->_fields["billing_state_province_id-{$self->_bltID}"]['is_required'] = TRUE;               }           }         } Then, in CRM/Core/Payment/Form.php I removed the is_required attribute from the state/province field. The only problem is that the red asterisk then disappears from the form element. I'm not much good with Smarty, so I just manually hacked the asterix into the template. But I guess it would be better to manipulate the smarty object and ensure that the template still thinks the field is required.
Hide
Neha Kulkarni added a comment -
checked in r26197
Show
Neha Kulkarni added a comment - checked in r26197

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: