CRM-9395 validate hook does not return errors array properly in J16+

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Major
    • Resolution: Fixed/Completed
    • Affects Version/s: 4.0.8
    • Fix Version/s: 4.2.0
    • Component/s: Core CiviCRM
    • Labels:
      None

      Description

      in Joomla 1.6+, the validate hook does not work correctly. while the hook itself is recognized, the errors array that should be returned is ignored by the form and so no validation occurs. the error would impact any hooks that work by returning a value to the parent code rather than handling with variables passed by reference (the more common behavior).

      see also: http://forum.civicrm.org/index.php/topic,22781.0.html

        Attachments

          Activity

          [CRM-9395] validate hook does not return errors array properly in J16+
          Brian Shaughnessy added a comment -

          the first patch in this issue was not merged into 4.1 and needs to be.
          additionally, we need to apply the attached patch to ensure we don't get array merge errors.

          Brian Shaughnessy added a comment -

          still running into some issues with this. and I'm a little uncertain how this plays out down the line.
          i'm using the validate hook, and here's what i'm seeing –

          if the hook returns a success (no errors) the result is:
          array ( 0 => 1 )

          if the hook returns an error, we get:
          array( 0 => array( field => msg ) )

          so the intent of the original modification was to collapse the array down. the problem is that we need to return $result = 1 if it's a success, and an array if it's a fail. so I can modify/patch. my concern is that i'm only using the validate hook as the test case. are there other hooks we need to account for with this?

          here's what I propose (and which seems to work fine for the validate hook:

          foreach ( $result as $res ) {
          if ( !is_array($res) )

          { $finalResult = $res; }

          else

          { $finalResult = array_merge( $finalResult, $res ); }

          }

          Donald A. Lobo added a comment -

          Maybe in 4.2 we should abandon backward compatibility for validate hook and also send in that parameter so folks can add / remove from it. Will make it more consistent with the other hooks (we should also check and ensure that if there are other hooks, we do the same)

          lobo

          Brian Shaughnessy added a comment -

          I need to revisit this. I ran into another scenario where the validate hook returns something like:

          Array
          (
          [0] => 1
          [1] => Array
          (
          [birth_date] => Birth Date is required.
          [gender_id] => Gender is required.
          )

          )

          which screws up our handling (which conditions on whether the return element is an array)

          Donald A. Lobo added a comment -

          so for 4.2 i created a new hook called:

          validateForm

          which basically takes in the error array as an argument. We avoid the whole "what should we return issue" and now conform to the other hooks. We'll obsolete validate hook in 4.3

          I'll document this once we branch the wiki for 4.3

          Donald A. Lobo added a comment -

          I documented on the wiki and also fixed the civitest.module.sample file to use the new version of the hook

            People

            • Assignee:
              Brian Shaughnessy
              Reporter:
              Brian Shaughnessy

              Dates

              • Created:
                Updated:
                Resolved: