Answers.Body: <p>@soupmagnet Welcome to CiviCRM world!</p>
  
  <p>You can alter the form elements or add your own form element to any CiviCRM forms using CiviCRM <a href="https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_buildForm/" rel="nofollow noreferrer">buildForm</a> hook. The <a href="https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_buildForm/" rel="nofollow noreferrer">documentation</a> provided good example on how to do it. Please implement this hook either in CiviCRM extension or Drupal module.</p>
  
  <p>HTH</p>
  
  <p>Pradeep</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-24T16:23:54.660Z
Answers.Text: I appreciate your input, but I've tried that (see my edit) and still not getting anything back.
Answers.UserDisplayName: soupmagnet
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-24T16:06:34.677Z
Answers.LastActivityDate: 2018-09-24T16:28:31.280Z
Answers.LastEditDate: 2018-09-24T16:28:31.280Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>I'm having trouble accessing the CiviCRM $form object on a Drupal site running CiviCRM. </p>
  
  <p>In Drupal, I can use hook_form_alter() anywhere in code and make changes to any form object in Drupal. I'm trying to do the same thing for a CiviCRM form, but none of the functions or hooks seem to give me access to the $form object.  </p>
  
  <p>Also, I'm attempting to do this from a custom script with Drupal and CiviCRM  bootstrapped.  If someone could point me in the right direction, I would be most grateful.</p>
  
  <p>[EDIT:] I've tried this, but can't get any data back for anything...</p>
  
  <pre><code>define('DRUPAL_ROOT', $_SERVER['DOCUMENT_ROOT']);
  require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
  drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
  
  eval(`cv php:boot`); // to bootstrap CiviCRM according to their documentation
  
  function mycustomhook_civicrm_buildForm($formName, &amp;$form) {
      dpm($form);
      dpr($form);
      kpr($form);
      var_dump($form);
      print_r($form);
  }
  </code></pre>
  
  <p>What am I missing?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-09-24T16:27:23.387Z
Comments.Text: On what form are you using this? Is mycustomhook module?
Comments.UserDisplayName: Pradeep Nayak
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-09-24T16:48:48.690Z
Comments.Text: This code is sitting in a single separate PHP script, which will eventually accept a GET request from an AJAX call.  The script should be able to edit the $form object before the form is submitted.  It is intended as a way to copy jQuery changes to the DOM, back to the database when the form is submitted.  The 'mycustomhook', is referencing the name of the theme in use, although not literally named "mycustomhook".
Comments.UserDisplayName: soupmagnet
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-09-24T17:13:02.037Z
Comments.Text: I think you should use it in module or extension. I don't recon if its invoked through theme
Comments.UserDisplayName: Pradeep Nayak
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-09-24T17:53:22.523Z
Comments.Text: I just tried doing this in a module and had the same results.
Comments.UserDisplayName: soupmagnet
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-09-24T17:54:35.260Z
Comments.Text: If the form you rendering is a civi form which extends CRM_Core_Form then the hook should get invoked
Comments.UserDisplayName: Pradeep Nayak
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-09-24T18:01:20.073Z
Comments.Text: The form is definitely a CiviCRM form, titled "CRM_Event_Form_Registration_Register".  I was able to get that ID through a dpm() call in the template.php.  In my module, I remembered to include civicrm as a dependency as well.  However, I still can't get anywhere near the $form object for some reason.
Comments.UserDisplayName: soupmagnet
Tags: <drupal><forms>
Title: Cant find a way to access the CiviCRM $form object in Drupal
ThreadText: # Cant find a way to access the CiviCRM $form object in Drupal
  
  (Asked by: username_0 on 2018-09-24)
  
  I'm having trouble accessing the CiviCRM $form object on a Drupal site running CiviCRM.
  
  In Drupal, I can use hook\_form\_alter() anywhere in code and make changes to any form object in Drupal. I'm trying to do the same thing for a CiviCRM form, but none of the functions or hooks seem to give me access to the $form object.
  
  Also, I'm attempting to do this from a custom script with Drupal and CiviCRM bootstrapped. If someone could point me in the right direction, I would be most grateful.
  
  [EDIT:] I've tried this, but can't get any data back for anything...
  
  ```
  define('DRUPAL_ROOT', $_SERVER['DOCUMENT_ROOT']);
  require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
  drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
  
  eval(`cv php:boot`); // to bootstrap CiviCRM according to their documentation
  
  function mycustomhook_civicrm_buildForm($formName, &$form) {
      dpm($form);
      dpr($form);
      kpr($form);
      var_dump($form);
      print_r($form);
  }
  
  ```
  
  What am I missing?
  
  **Tags:** drupal, forms
  
  > **Comments:**
  > **username_1**: On what form are you using this? Is mycustomhook module?  
  > **username_0**: This code is sitting in a single separate PHP script, which will eventually accept a GET request from an AJAX call.  The script should be able to edit the $form object before the form is submitted.  It is intended as a way to copy jQuery changes to the DOM, back to the database when the form is submitted.  The 'mycustomhook', is referencing the name of the theme in use, although not literally named "mycustomhook".  
  > **username_1**: I think you should use it in module or extension. I don't recon if its invoked through theme  
  > **username_0**: I just tried doing this in a module and had the same results.  
  > **username_1**: If the form you rendering is a civi form which extends CRM_Core_Form then the hook should get invoked  
  > **username_0**: The form is definitely a CiviCRM form, titled "CRM_Event_Form_Registration_Register".  I was able to get that ID through a dpm() call in the template.php.  In my module, I remembered to include civicrm as a dependency as well.  However, I still can't get anywhere near the $form object for some reason.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-09-24. Score: 1
  
  @username_0 Welcome to CiviCRM world!
  
  You can alter the form elements or add your own form element to any CiviCRM forms using CiviCRM [buildForm](https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_buildForm/) hook. The [documentation](https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_buildForm/) provided good example on how to do it. Please implement this hook either in CiviCRM extension or Drupal module.
  
  HTH
  
  username_1
  
  > **Comments:**
  > **username_0**: I appreciate your input, but I've tried that (see my edit) and still not getting anything back.  
  
  ---
  
  