You are here

function fb_ahah_bind_form in Drupal for Facebook 5

Same name and namespace in other branches
  1. 5.2 fb_form.module \fb_ahah_bind_form()
  2. 6.2 fb_form.module \fb_ahah_bind_form()

Support for AHAH in forms.

This is intended to be compatible with the syntax of ahah_forms.module. However, much of what that module does requires jquery. In FBML we have to jquery and are therefor limited in what we can support. For example, we only support the id selectors, you can't specify selector in your ahah_bindings.

1 string reference to 'fb_ahah_bind_form'
fb_form_form_alter in ./fb_form.module
hook_form_alter.

File

./fb_form.module, line 59
This module defines facebook-specific form elements for use with Drupal's form API.

Code

function fb_ahah_bind_form($form) {
  static $one_time_only;

  // Facebook javascript appears to work only when the user is logged in.  Not
  // sure whether this is on purpose or not.  So we only activate AHAH when
  // user is logged in.
  global $fb;
  if ($fb && $fb->api_client->added && function_exists('ahah_forms_scan_form_children')) {
    $bindings = array();
    ahah_forms_scan_form_children($form, $form['#id'], $bindings);

    //	drupal_set_message( "After Scan: Wrapper Bindings = " . dprint_r( $bindings, TRUE ) );
    if (count($bindings) > 0) {
      if (!$one_time_only) {

        //add in required javascript files
        $module_path = drupal_get_path('module', 'ahah_forms');
        fb_add_js(drupal_get_path('module', 'fb_form') . '/fb_ahah_forms.js');
        drupal_add_js(array(
          'ahah' => array(
            'basePaths' => array(
              'base' => base_path(),
              'module' => $module_path,
            ),
            'bindings' => array(
              $bindings,
            ),
          ),
        ), 'setting', 'fbjs');
        $one_time_only = TRUE;
      }
      else {
        drupal_add_js(array(
          'ahah' => array(
            'bindings' => array(
              $bindings,
            ),
          ),
        ), 'setting', 'fbjs');
      }
    }
  }
  return $form;
}