My Webprojects, Software, Work

Gravity Forms List Field Type: Make sure to have a minum number of rows

I recently ran in the problem that a client wanted an application form which is easy peasy built with Gravity forms.

They also wanted to ensure that at least 3 previous jobs are filled out. The previoius employers field was a list field (Name, Address, Time worke there etc.)

If you ever need to enforce a minumum amount of list items use the Gravity Form field validation :

add_filter( 'gform_field_validation_1_27', 'force_three_rows_in_lists', 10, 4 );

function force_three_rows_in_lists($result, $value, $form, $field){

if ( $result['is_valid'] && count($value) < 3) {
$result['is_valid'] = false;
$result['message'] = 'Please enter at least 3 previous employers (Use the + Button at the end to add more lines)';
}

return $result;
} 

The count($value)< 3 is the important part, the $value is an array of rows that are submitted.

 

More Info about that filter in the Gravity Froms Documentation.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s