Answers.Body: <p>The callback receives 5 params, so your code should read:</p>
  <pre><code>add_action( 'civicrm_validateForm', 'validate_org_form', 10, 5 );
  </code></pre>
  <p>BTW it's syntactically preferable to use <code>add_action</code> since there's nothing returned by the function as there is with <code>add_filter</code>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-09-20T14:24:50.763Z
Answers.Text: Schoolboy error - thanks for responding!
Answers.UserDisplayName: christodhunter
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-09-20T10:47:45.127Z
Answers.LastActivityDate: 2022-09-20T10:47:45.127Z
Answers.UserDisplayName: Christian Wach
Body: <p>I'm trying to implement some custom validation on a contribution form on WordPress.</p>
  <p>I have this in my functions.php:</p>
  <p>add_filter( 'civicrm_validateForm', 'validate_org_form', 10, 4 );
  function validate_org_form($formName, &amp;$fields, &amp;$files, &amp;$form, &amp;$errors) {</p>
  <p>But I get an error when the form submits:</p>
  <p>Uncaught ArgumentCountError: Too few arguments to function validate_org_form</p>
  <p>So it looks like this hook doesn't work the same for contribution forms as it does for others.</p>
  <p>What I'm trying to do is check if an organisation already has a membership when a user is contribution on behalf of an organisation. I want to run an API call to check for memberships of the same type and fail the contribution with a message if any exist.</p>
  
Tags: <wordpress><civicontribute>
Title: Custom validation on contribution form?
ThreadText: # Custom validation on contribution form?
  
  (Asked by: username_0 on 2022-09-19)
  
  I'm trying to implement some custom validation on a contribution form on WordPress.
  
  I have this in my functions.php:
  
  add\_filter( 'civicrm\_validateForm', 'validate\_org\_form', 10, 4 );
  function validate\_org\_form($formName, &$fields, &$files, &$form, &$errors) {
  
  But I get an error when the form submits:
  
  Uncaught ArgumentCountError: Too few arguments to function validate\_org\_form
  
  So it looks like this hook doesn't work the same for contribution forms as it does for others.
  
  What I'm trying to do is check if an organisation already has a membership when a user is contribution on behalf of an organisation. I want to run an API call to check for memberships of the same type and fail the contribution with a message if any exist.
  
  **Tags:** wordpress, civicontribute
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-09-20. Score: 1 | Accepted answer
  
  The callback receives 5 params, so your code should read:
  add_action( 'civicrm_validateForm', 'validate_org_form', 10, 5 );
  
  BTW it's syntactically preferable to use add_action since there's nothing returned by the function as there is with add_filter.
  
  > **Comments:**
  > **username_0**: Schoolboy error - thanks for responding!  
  
  ---
  
  