Custom Processor Not Working
-
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() );
- The topic ‘Custom Processor Not Working’ is closed to new replies.