0

I'm trying to modify the user_profile_form, but it isn't working. My regular user edit information shows up, but not my profile2 information.

    function MY_MODULE_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'user_register_form' || $form_id == 'user_profile_form') {
    $form['#attached']['js'][] = drupal_get_path('module', 'conduit') . '/js/jvectormap.min.js'; // You should place jvectormap js files into MYMODULE/js folder
    $form['#attached']['js'][] = drupal_get_path('module', 'conduit') . '/js/jquery-jvectormap-mi-counties.js'; // This is US counties generated file (see #1).
    $form['#attached']['js'][] = drupal_get_path('module', 'conduit') . '/js/county-select.js';
    $form['mi_container'] = array(
        '#type' => "container",
        '#states' => array(
            'visible' => array(// action to take.
                'select[name="profile_main[field_states][und]"]' => array('value' => 187),
            ),
        ),
    );
    $form['mi_container']['micounties_markup'] = array(
        '#markup' => '<div id="micounties" style="width: 600px; height: 400px"></div>', // Define own width and height.
    );

  }
}

Why wouldn't this work?

1 Answer 1

1

You've implemented hook_form_FORM_ID_alter(), which only fires for a single form (user_register_form in this case).

If you want to catch multiple forms in a single function, you need hook_form_alter():

function MY_MODULE_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'user_register_form' || $form_id == 'user_profile_form') {
  ...
}
5
  • Wow, I didn't even notice that. Thank you. Is there anyway to delete a question?
    – Jack Ryan
    Commented Aug 23, 2014 at 18:59
  • Looks like you found it ;)
    – Clive
    Commented Aug 23, 2014 at 19:00
  • One thing I'm noticing is that even with the form alter changed, is that it's still not showing me my profile2 information, so I'm going to undelete the question and change it.
    – Jack Ryan
    Commented Aug 23, 2014 at 19:04
  • 1
    One thing I'm thinking it might be caused by is module weight, will test.
    – Jack Ryan
    Commented Aug 23, 2014 at 19:15
  • It seems like it may be related to this. I'll probably give you the answer as you set me on the right path.
    – Jack Ryan
    Commented Aug 23, 2014 at 19:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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