Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-3264

Profile form does not restrict states by country

    Details

    • Type: Improvement
    • Status: Done/Fixed
    • Priority: Major
    • Resolution: Fixed/Completed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.2.0
    • Component/s: Core CiviCRM
    • Labels:
      None

      Description

      When using the profile retrieved with crm_uf_get_profile_html_by_id(), with a profile with country and state fields, all of the states are shown. While the CiviCRM edit page attempts to restrict the state list with AJAX,

      I used a simpler jquery solution in a custom Drupal module. I don't think that CiviCRM uses, jquery, so I don't know if this will be useful to CiviCRM.

      Here's the Drupal solution, the jquery is attached.

      <code>
      function _myexample_civicrm_get_profile_html($contact_id, $profile_id) {
      $path = drupal_get_path('module', 'civicrm') .'/../';
      require_once($path .'api/UFGroup.php');
      require_once($path .'CRM/Core/DAO/StateProvince.php');

      // Include a jquery setting that maps states to countries.
      $object =& new CRM_Core_DAO_StateProvince;
      $object->find();
      $states = array();
      while ($object->fetch())

      { $states[$object->id] = $object->country_id; }

      drupal_add_js(array('states' => $states), 'setting');
      // Include the jquery to limit the state select box by country.
      drupal_add_js(drupal_get_path('module', 'myexample') .'/civicrm-state.js');

      return crm_uf_get_profile_html_by_id($contact_id, $profile_id, CRM_Core_Action::UPDATE, false, true);
      }
      </code>

        Attachments

          Activity

            People

            • Assignee:
              amit Amiteshwar Prasad
              Reporter:
              douggreen Doug Green
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: