Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Gravity Wiz // Require All Columns of List Field
<?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
You can’t perform that action at this time.