- if (CRM_Utils_Array::value('is_for_organization', $this->_values)) {
- $this->_onbehalf = TRUE;
- CRM_Contribute_Form_Contribution_OnBehalfOf::preProcess($this);
+ if (!empty($this->_values['is_for_organization'])) {
+ if ($this->_values['is_for_organization'] == 2) {
+ $this->_onBehalfRequired = TRUE;
+ }
+ // Add organization profile if 1 of the following are true:
+ // If the org profile is required
+ if ($this->_onBehalfRequired ||
+ // Or we are building the form for the first time
+ empty($_POST) ||
+ // Or the user has submitted the form and checked the "On Behalf" checkbox
+ !empty($_POST['is_for_organization'])
+ ) {
+ $this->_onbehalf = TRUE;
+ CRM_Contribute_Form_Contribution_OnBehalfOf::preProcess($this);
+ }