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, 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?
CRM_Contribute_Form_ContributionBase
class, the id can be retrieve via_id
. The problem with profile forms extendingCRM_Profile_Form
is that thegid
is aprotected int
with no way of accessing it. This is a bummer, I am still trying to find a way._gid
property. This can be done by calling$form->get_var('_gid')
. I found some example code within a CiviCRM forum postgetVar
notget_var
but yes that's right. Nice work finding the solution.