kodie / gravityforms-repeater

A Gravity Forms add-on that allows specified groups of fields to be repeated by the user.
59 stars 58 forks source link

Problem with validation #68

Open elrocka opened 8 years ago

elrocka commented 8 years ago

I cant validate the field input when send the number 0. The validation work with "00", but dont work with "0". Please, if you have a solution for this give it to me.

Thanks!

elrocka commented 7 years ago

This is was my primitive solution:

add_filter( 'gform_validation', 'custom_validation' ); function custom_validation( $validation_result ) { $form = $validation_result['form'];

$mystring = $_POST['input_10'];
$findme1  = 'repeatCount\":1';
$findme2  = 'repeatCount\":2';
$findme3  = 'repeatCount\":3';
$findme4  = 'repeatCount\":4';
$pos1 = strpos($mystring, $findme1);
$pos2 = strpos($mystring, $findme2);
$pos3 = strpos($mystring, $findme3);
$pos4 = strpos($mystring, $findme4);
$num1= rgpost( 'input_15-1-1' ) ;
$num2= rgpost( 'input_15-1-2' ) ;
$num3= rgpost( 'input_15-1-3' ) ;
$num4= rgpost( 'input_15-1-4' ) ;

if(($pos1) AND $num1 == "") {
    $validation_result['is_valid'] = false;
} 

if(($pos2) AND ($num1 == "" OR $num2 == "")) {
    $validation_result['is_valid'] = false;
} 

if(($pos3) AND ($num1 == "" OR $num2 == "" OR $num3 == "")) {
    $validation_result['is_valid'] = false;
} 

if(($pos4) AND ($num1 == "" OR $num2 == "" OR $num3 == "" OR $num4 == "")) {
    $validation_result['is_valid'] = false;
} 

$validation_result['form'] = $form;
return $validation_result;

}

add_action( 'gform_pre_submission', 'pre_submission_handler' ); function pre_submission_handler( $form ) { if($_POST['input_15-1-1'] == 0){ $_POST['input_15-1-1']='cero'; } if($_POST['input_15-1-2'] == 0){ $_POST['input_15-1-2']='cero'; } if($_POST['input_15-1-3'] == 0){ $_POST['input_15-1-3']='cero'; } if($_POST['input_15-1-4'] == 0){ $_POST['input_15-1-4']='cero'; } }

And add to the array, the number 0 as "cero"

Regards