• Resolved PaulH

    (@paulhuckstepp)


    I have a rather extensive form with 100+ fields and I’ve created a custom processor that takes up to 6 fields (magic tags) and returns an error if they do not add up to 100 (percent). I set it up all correctly with the magic tags for the 6 fields in question but the processor fails to run.

    So, I created a secondary test form with the exact same 6 fields in, wired up the processor in the same way and tested it – it worked and returned the error correctly.

    I’ve tried everything short of rebuilding the whole form (which took an entire day to build) but it never seems to call the actual processor – even if I force the processor to always return an error!

    What could be wrong?

    PS. Caldera Forms gets very very slow when you have 100+ fields in a layout.

    Plugin Code (excluding plugin info comments)

    );
    
        return $processors;
    }
    
    /**
     * Processor fields
     *
     * @return array
     */
    function dlynxext_cf_validator_fields(){
        return array(
            array(
                'id' => 'percent_field_1',
                'type' => 'text',
                'required' => true,
                'magic' => true,
                'label' => __( 'Field 1 to validate', 'my-text-domain' )
            ),
            array(
                'id' => 'percent_field_2',
                'type' => 'text',
                'required' => false,
                'magic' => true,
                'label' => __( 'Field 2 to validate', 'my-text-domain' )
            ),
            array(
                'id' => 'percent_field_3',
                'type' => 'text',
                'required' => false,
                'magic' => true,
                'label' => __( 'Field 3 to validate', 'my-text-domain' )
            ),
            array(
                'id' => 'percent_field_4',
                'type' => 'text',
                'required' => false,
                'magic' => true,
                'label' => __( 'Field 4 to validate', 'my-text-domain' )
            ),
            array(
                'id' => 'percent_field_5',
                'type' => 'text',
                'required' => false,
                'magic' => true,
                'label' => __( 'Field 5 to validate', 'my-text-domain' )
            ),
            array(
                'id' => 'percent_field_6',
                'type' => 'text',
                'required' => false,
                'magic' => true,
                'label' => __( 'Field 6 to validate', 'my-text-domain' )
            ),
        );
    }
    
    /**
     * Run field validation
     *
     * @param array $config Processor config
     * @param array $form Form config
     *
     * @return array|void Error array if needed, else void.
     */
    function percent_group_validator( array $config, array $form ){
    
      $data = new Caldera_Forms_Processor_Get_Data( $config, $form, dlynxext_cf_validator_fields() );
    
        $value[] = $data->get_value( 'percent_field_1' );
        $value[] = $data->get_value( 'percent_field_2' );
        $value[] = $data->get_value( 'percent_field_3' );
        $value[] = $data->get_value( 'percent_field_4' );
        $value[] = $data->get_value( 'percent_field_5' );
        $value[] = $data->get_value( 'percent_field_6' );
    
        $total=0;
        foreach($value as $v){
          $total += $v;
        }
    
        //if not valid, return an error
        if( $total != 100 ){
    
            //get ID of field to put error on
            $fields = $data->get_fields();
            $field_id = $fields[ 'percent_field_1' ][ 'config_field' ];
    
            //Get label of field to use in error message above form
            $field = $form[ 'fields' ][ $field_id ];
            $label = $field[ 'label' ];
    
            //this is error data to send back
            return array(
                'type' => 'error',
    
                'fields' => array(
                    //This error message will be shown below the field that we are validating
                    $field_id => __( 'This group of fields must add up to 100.', 'text-domain' )
                )
            );
        }
    
        //If everything is good, don't return anything!
    
    }

    Config.php code:
    echo Caldera_Forms_Processor_UI::config_fields( dlynxext_cf_validator_fields() );

    • This topic was modified 7 years ago by PaulH.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter PaulH

    (@paulhuckstepp)

    Update:

    I’ve worked out whats going on. When the form is validated the default built in validation rules are checked and errors are displayed but the custom processors are not.

    If none of the default validation rules trigger a validation error then the custom processors are performed and those validation errors are shown.

    This isn’t what should happen as far as I know. All validations should be performed and results displayed – otherwise the user will fill in the form, resolve any validation issues (required fields, etc), click submit and then find new validation errors to fix.

    Can this be corrected easily?

    Plugin Contributor christiechirinos

    (@christiechirinos)

    Hi Paul,

    Thanks for using Caldera Forms. Thanks for the detail in your post. Just so you know, do not offer support for Caldera Forms via this board. You might get help from the power users on here, but to get support from us we ask that you purchase Caldera Forms Pro. This model is how we are able to offer a powerful product for free, but also have a professional team supports and updates the product every day. Plans are affordable, starting at $14.99/month with no contract.

    You can browse plans at https://calderaforms.com/pro/. If you are already a paying subscriber, you can request support at https://calderaforms.com/support/.

    Alternatively, you can join our Facebook community group and collaborate with other free users of Caldera Forms: https://www.facebook.com/groups/651862761663883

    Sorry about the hassle, and thanks for understanding that this is separate channel allows us to ensure that we are able to continue to develop great products for you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Processor Not Working’ is closed to new replies.