1

I have a contact us form, that I want only users from the US to see, fill and submit. And the other users to see that form but a message says "web form is not available in your country" if the user is from outside the sates. Is there a module to do so? or I just have to make my own? thanks.

3

You can use a module like Smart IP http://drupal.org/project/smart_ip, GeoIP http://drupal.org/project/geoip or just the Maxmind Geolite http://www.maxmind.com/app/geolitecountry table to look use the IP address of the user to determine the country.

Then use hook_nodeapi() or hook_node_view(), depending on if you are using Drupal 6 or 7, to redirect the person based on the country.

The pseudo code would look something like this (Drupal 6, using Geoip):

function MYMODULE_custom_nodeapi(&$node, $op) {
  switch ($op) {
    case 'view':
      if ($node->nid == 'NODEID OF WEBFORM') {
        $country = geoip_country_code();
        if (isset($country) && $country != 'us') {
          drupal_goto('node/' . NODEID OF REDIRECT PAGE'); 
        }
      }
     break;
  }
}

edit: When I saw 'webform' I assumed you meant using the webform module, hence the nodeapi, but if you are using the basic site contact form you can use hook_menu and create a new callback for the path of the form you are using and create the same kind of check as above.

| improve this answer | |
  • Thanks for the answer, ill try this method tonight and will come back to you. thank you so much sir. – saadlulu Jan 30 '12 at 8:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.