Created
September 12, 2012 18:02
-
-
Save spivurno/3708669 to your computer and use it in GitHub Desktop.
Gravity Wiz // Require All Columns of List Field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Require All Columns of List Field | |
* http://gravitywiz.com/2012/07/23/require-all-columns-of-list-field/ | |
*/ | |
add_filter('gform_validation', 'gwiz_require_all_list_columns'); | |
function gwiz_require_all_list_columns($validation_result) { | |
$form = $validation_result['form']; | |
$new_validation_error = false; | |
foreach($form['fields'] as &$field) { | |
if($field['type'] != 'list' || !$field['isRequired']) | |
continue; | |
$values = rgpost("input_{$field['id']}"); | |
foreach($values as $value) { | |
if(empty($value)) { | |
$new_validation_error = true; | |
$field['failed_validation'] = true; | |
$field['validation_message'] = $field['errorMessage'] ? $field['errorMessage'] : 'All inputs must be filled out.'; | |
} | |
} | |
} | |
$validation_result['form'] = $form; | |
$validation_result['is_valid'] = $new_validation_error ? false : $validation_result['is_valid']; | |
return $validation_result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment