I'm using SMS User module which validates users' mobile numbers. There's a select box and all countries in it. Users select country and write their mobile numbers.

I want to show only 3 countries in it, but there's no option in admin panel. I looked up the sms_user table. There is a gateway column and country codes writing. That's all.

How can I modify the country list? When I looked into the module code, I found nothing about countries.

  • 3
    You can use hook_form_alter() and unset the rest of the values. – mohit_rocks Dec 27 '12 at 4:48
  • thanks, but sms_user module in here sites/all/modules/smsframework/modules/sms_user and in sms_user.info project name is smsframework and also the module sms_clickatell in sites/all/modules/sms_clickatell so i add in template.php this lines to check. – turkaze Dec 27 '12 at 22:25
  • 1-function sms_clickatell_form_alter(&$form, &$form_state, $form_id) { if ($form['#id'] == 'sms-user-settings-add-form') { // Rename the submit button $form['submit']['#value'] = t("Save"); } } – turkaze Dec 27 '12 at 22:25
  • function smsframework_form_alter(&$form, &$form_state, $form_id) { if ($form['#id'] == 'sms-user-settings-add-form') { // Rename the submit button $form['submit']['#value'] = t("Save"); } } – turkaze Dec 27 '12 at 22:26
  • After i clear cahches but nothing change. i want to modify select box option but firstly i test if submit value changes. – turkaze Dec 27 '12 at 22:28

I think you are trying to shorten the country select box in user registration form and user edit form. You should not hack the contributed modules. You could create your own module and override the forms using hook_form_alter().

I assume you have a custom module and you could implement hook_form_alter() to update the country list as you need. Here is the code in mymodule.module tested in my test site:

function mymodule_form_alter(&$form, &$form_state, $form_id) {
    if( $form_id == 'user_register_form' || $form_id == 'user_profile_form' ){
        $countries = array( // define the countries you want
            93  => 'Afghanistan', 
            355 => 'Albania', 
            213 => 'Algeria'
        $form['sms_user']['gateway']['country']['#options'] = $countries; // update sms country select box.

But, to access the field group sms_user, your module must have the heaviest weight, otherwise you won't be able to update $form['sms_user']['gateway']['country'].
You can make sure your module is heaviest by creating yourmodulename.install.

 * Implementation of hook_install()
function mymodule_install(){
    # Fetch max module weight from "system" table.
    $max_weight = db_query("SELECT MAX(weight) FROM {system} WHERE type = 'module'")->fetchField();
    # Make sure this module is the heaviest one in order to run last
        ->fields(array('weight' => $max_weight+1))
        ->condition('name', 'mymodule')
 * Implementation of hook_uninstall()
function mymodule_uninstall(){
        ->condition('name', 'mymodule')

If you are expert, you can tweak the weight field of your module in the system table to make it heaviest without creating yourmodulename.install, but not recommended. You may need to flush all caches after you implemented this.

  • thanks, i solve my problem another way and your answer help me. – turkaze Dec 29 '12 at 17:30

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.