Answers.Body: <p>In principle the names are based on the files, so the form which is CRM/Contact/Form/Contact.php will be CRM_Contact_Form_Contact.</p>
  
  <p>AFAIK the name of the form will always be commented if you inspect the form with Firebug, Firefox or Chrome.</p>
  
  <p>In some cases forms will be called from pages (like the contribution page). This is kinda hard to find out, I always do a post hook in my extensions to log the $formName parameter to find out what forms are called during the process.</p>
  
  <p>AFAIK you will need to include a call to the form hook to make sure your customized form is also usable in a validateForm hook (see below). But I would certainly try first if the parent CRM_Core_Form does not handle that and you can indeed already check for your customized form name.</p>
  
  <pre><code>    CRM_Utils_Hook::validateForm(
    get_class($this),
    $this-&gt;_submitValues,
    $this-&gt;_submitFiles,
    $this,
    $hookErrors
  );
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-22T11:57:13.963Z
Answers.Text: Hmm that sounds like a bit of overkill. It's too bad that profile/contribution title values are not made available through the `$form` parameter. It would make differentiating between forms for validation much simpler.
Answers.UserDisplayName: Ivan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-22T12:03:26.813Z
Answers.Text: Well, if you just check the formNames once you will get them! I have recently done some stuff on contribution pages so I think you can get there without too much hardship?
Answers.UserDisplayName: ErikH - CiviCooP
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-22T11:33:35.020Z
Answers.LastActivityDate: 2018-05-22T11:33:35.020Z
Answers.UserDisplayName: ErikH - CiviCooP
Answers.Body: <p>The form names are usually the same as the class name of the form object. And the class names follow a pattern as CRM_aaa_Form_bbb meaning that this class resides in the file CRM/aaa/Form/bbb.php </p>
  
  <p>There is no possibility to define custom form names. Or at least I am not aware of it and I would object against it because then the same form could be named differently in different installations and that makes the whole thing more complex. </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-22T11:31:29.713Z
Answers.LastActivityDate: 2018-05-22T11:31:29.713Z
Answers.UserDisplayName: Jaap Jansma - CiviCooP
Body: <p>I am attempting to perform form validation on various CiviCRM forms (profile forms and forms within contribution pages) by hooking into <code>hook_civicrm_validateForm</code>. </p>
  
  <p>In my php code, I would like to differentiate between the different forms so that I can execute appropriate validation functions. According to the <a href="https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_validateForm/" rel="nofollow noreferrer">CiviCRM documentation</a>, this can be done by checking against the <code>$formName</code> parameter. </p>
  
  <p>While debugging, I found out that a contribution page I am using has a <code>$formName</code> of <code>CRM_Contribute_Form_Contribution_Main</code>. For a profile form its <code>$formName</code> is <code>CRM_Profile_Form_Edit</code>.</p>
  
  <p>Is there a way of finding out how the names of form are defined? If so, does CiviCRM supporting assigning forms with custom form names? </p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-02T08:01:57.873Z
Comments.Text: Yes I am. I would like to also find particular profiles via their gid. After taking a look at the class reference of the `CRM_Contribute_Form_ContributionBase` class, the id can be retrieve via `_id`. The problem with profile forms extending  `CRM_Profile_Form` is that the `gid` is a `protected int` with no way of accessing it. This is a bummer, I am still trying to find a way.
Comments.UserDisplayName: Ivan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-04T07:36:23.403Z
Comments.Text: UPDATE: actually I found out it is indeed possible to read the `_gid` property. This can be done by calling `$form->get_var('_gid')`. I found some example code within a [CiviCRM forum post](https://forum.civicrm.org/index.php%3Ftopic=17549.0.html)
Comments.UserDisplayName: Ivan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-04T15:46:11.110Z
Comments.Text: Actually the function name is `getVar` not `get_var` but yes that's right. Nice work finding the solution.
Comments.UserDisplayName: Coleman
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-01T22:05:40.677Z
Comments.Text: Are you trying to find a particular profile form? That can be achieved by checking the gid as well as the form name.
Comments.UserDisplayName: Coleman
Tags: <profile><contribution-page><php><hooks><forms>
Title: How are CiviCRM form names defined (civicrm_validateForm)?
ThreadText: # How are CiviCRM form names defined (civicrm_validateForm)?
  
  (Asked by: username_0 on 2018-05-22)
  
  I am attempting to perform form validation on various CiviCRM forms (profile forms and forms within contribution pages) by hooking into `hook_civicrm_validateForm`.
  
  In my php code, I would like to differentiate between the different forms so that I can execute appropriate validation functions. According to the [CiviCRM documentation](https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_validateForm/), this can be done by checking against the `$formName` parameter.
  
  While debugging, I found out that a contribution page I am using has a `$formName` of `CRM_Contribute_Form_Contribution_Main`. For a profile form its `$formName` is `CRM_Profile_Form_Edit`.
  
  Is there a way of finding out how the names of form are defined? If so, does CiviCRM supporting assigning forms with custom form names?
  
  **Tags:** profile, contribution-page, php, hooks, forms
  
  > **Comments:**
  > **username_1**: Are you trying to find a particular profile form? That can be achieved by checking the gid as well as the form name.  
  > **username_0**: Yes I am. I would like to also find particular profiles via their gid. After taking a look at the class reference of the `CRM_Contribute_Form_ContributionBase` class, the id can be retrieve via `_id`. The problem with profile forms extending  `CRM_Profile_Form` is that the `gid` is a `protected int` with no way of accessing it. This is a bummer, I am still trying to find a way.  
  > **username_0**: UPDATE: actually I found out it is indeed possible to read the `_gid` property. This can be done by calling `$form->get_var('_gid')`. I found some example code within a [CiviCRM forum post](https://forum.civicrm.org/index.php%3Ftopic=17549.0.html)  
  > **username_1**: Actually the function name is `getVar` not `get_var` but yes that's right. Nice work finding the solution.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2018-05-22. Score: 2 | Accepted answer
  
  In principle the names are based on the files, so the form which is CRM/Contact/Form/Contact.php will be CRM_Contact_Form_Contact.
  AFAIK the name of the form will always be commented if you inspect the form with Firebug, Firefox or Chrome.
  In some cases forms will be called from pages (like the contribution page). This is kinda hard to find out, I always do a post hook in my extensions to log the $formName parameter to find out what forms are called during the process.
  AFAIK you will need to include a call to the form hook to make sure your customized form is also usable in a validateForm hook (see below). But I would certainly try first if the parent CRM_Core_Form does not handle that and you can indeed already check for your customized form name.
      CRM_Utils_Hook::validateForm(
    get_class($this),
    $this->_submitValues,
    $this->_submitFiles,
    $this,
    $hookErrors
  );
  
  > **Comments:**
  > **username_0**: Hmm that sounds like a bit of overkill. It's too bad that profile/contribution title values are not made available through the `$form` parameter. It would make differentiating between forms for validation much simpler.  
  > **username_2**: Well, if you just check the formNames once you will get them! I have recently done some stuff on contribution pages so I think you can get there without too much hardship?  
  
  ---
  
  ### Answer by username_3 on 2018-05-22. Score: 0
  
  The form names are usually the same as the class name of the form object. And the class names follow a pattern as CRM\_aaa\_Form\_bbb meaning that this class resides in the file CRM/aaa/Form/bbb.php
  
  There is no possibility to define custom form names. Or at least I am not aware of it and I would object against it because then the same form could be named differently in different installations and that makes the whole thing more complex.
  
  
  ---
  
  