Plugin Directory

Changeset 1519338


Ignore:
Timestamp:
10/21/2016 03:38:13 PM (9 years ago)
Author:
thebluecube
Message:

Fixing a bug which was caused by applying a custom validation to a required date field with the type of dropdown.

Location:
bluecube-mighty-gravity-forms
Files:
7 added
2 edited

Legend:

Unmodified
Added
Removed
  • bluecube-mighty-gravity-forms/trunk/class/Mighty_Gravity_Forms.php

    r1516705 r1519338  
    643643
    644644    /**
     645     * Our custom validation must take place before some of the
     646     * built-in validation e.g. `required` value validation.
     647     * @param $field
     648     * @return bool
     649     */
     650    protected function shouldNotBeValidatedWithCustomFunctions($field) {
     651
     652        $field_value = rgpost('input_' . $field->id);
     653        $should_not_be_validated = false;
     654
     655        // Is it required with no value?
     656        // If so, we would not want to apply the custom validation
     657        // because the built-in `require` validation should be returned
     658        // by Gravity Forms
     659        if ($field->isRequired) {
     660
     661            if (is_array($field_value)) {
     662
     663                if (empty($field_value)) {
     664                    $should_not_be_validated = true;
     665                } elseif($field->type == 'date') {
     666                    // For date fields, all the items must have non-empty values
     667                    if ( in_array('', $field_value) ) {
     668                        $should_not_be_validated = true;
     669                    }
     670                }
     671
     672            } elseif ($field_value == '') {
     673                $should_not_be_validated = true;
     674            }
     675        }
     676
     677        return $should_not_be_validated;
     678    }
     679
     680    /**
    645681     * Enforces the custom validation rule
    646682     * @param $validation_rule
     
    649685    protected function customValidationCheck($validation_rule, $field) {
    650686
    651         // Ignore the non-required field with no value
    652         $field_value = rgpost('input_' . $field->id);
    653         if (
    654             ($field_value == '' && ! $field->isRequired)
    655             || $field->validation_message != ''
    656         ) {
    657             // There's no need for custom validation
     687        if ($this->shouldNotBeValidatedWithCustomFunctions($field))
    658688            return;
    659         }
    660689
    661690        $function_name = $validation_rule[1];
  • bluecube-mighty-gravity-forms/trunk/readme.txt

    r1516705 r1519338  
    55Requires at least: 4.6
    66Tested up to: 4.6.1
    7 Stable tag: 1.1.3
     7Stable tag: 1.1.4
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3535== Changelog ==
    3636
     37= 1.1.4 =
     38* Fixing a bug which was caused by applying a custom validation to a required date field with the type of dropdown.
     39
    3740= 1.1.3 =
    3841* Fixing a bug which sent unintentional headers.
Note: See TracChangeset for help on using the changeset viewer.