Skip to content

How do I let people pick a course date with a seat limit in Gravity Forms?

Fill a Drop Down field from your list of dates with one PHP function and store the ID of each date as the value, not the date itself. On submit, the form rejects a date that is already full, and notifications sent in the background need one more filter so they show the date instead of its ID. Three filters fill the field for display, validation and submission, and notifications sent in the background need a fourth, gform_form_pre_process_async_task. A full date is rejected in gform_field_validation. The code below ran on November 30, 2026 on a test installation with Gravity Forms 3.2.3.1, without an add-on, and every result in this article comes from that run.

Which three filters fill a choice field?

gform_pre_render, gform_pre_validation and gform_pre_submission_filter fill the field for display, validation and submission. The documentation of gform_pre_render says the filter "should be used in conjunction with the gform_pre_validation, gform_pre_submission_filter, and gform_admin_pre_render filters", read on November 30, 2026. The fourth filter, gform_admin_pre_render, runs "before the entry detail is displayed" (documentation); the code below does not use it, and we did not test the entry view in the admin.

The documentation of gform_pre_submission_filter says it "is executed after form validation, but before any notifications are sent and the entry is stored". The whole code fits in one file under wp-content/mu-plugins/:

<?php
/**
 * Plugin Name: Course date with seat limit
 */

// Your dates: ID => text and seat limit. Replace this with your own data source.
function course_dates() {
	return array(
		101 => array( 'text' => 'Pottery, ' . date( 'F j, Y, g:i a', strtotime( '2027-01-12 18:00' ) ) . ', Zurich', 'seats' => 8 ),
		102 => array( 'text' => 'Pottery, ' . date( 'F j, Y, g:i a', strtotime( '2027-01-19 18:00' ) ) . ', Zurich', 'seats' => 1 ),
	);
}

// Seats taken = active entries that hold this date ID in the field.
function course_date_taken( $form_id, $field_id, $date_id ) {
	return GFAPI::count_entries( $form_id, array(
		'status'        => 'active',
		'field_filters' => array( array( 'key' => (string) $field_id, 'value' => (string) $date_id ) ),
	) );
}

// One function fills the field for display, validation and submission.
function course_date_choices( $form ) {
	foreach ( $form['fields'] as $field ) {
		if ( strpos( (string) $field->cssClass, 'course-date' ) === false ) {
			continue;
		}
		$choices = array();
		foreach ( course_dates() as $id => $date ) {
			$text = $date['text'];
			if ( 'gform_pre_render' === current_filter() ) {
				$left  = $date['seats'] - course_date_taken( $form['id'], $field->id, $id );
				$text .= $left > 0 ? " ($left left)" : ' (full)';
			}
			$choices[] = array( 'text' => $text, 'value' => (string) $id );
		}
		$field->choices = $choices;
	}
	return $form;
}
add_filter( 'gform_pre_render', 'course_date_choices' );
add_filter( 'gform_pre_validation', 'course_date_choices' );
add_filter( 'gform_pre_submission_filter', 'course_date_choices' );
// Background notifications load the form again, so fill the field there too.
add_filter( 'gform_form_pre_process_async_task', 'course_date_choices' );

// On submit: reject a value that is not a date, and a date that is full.
add_filter( 'gform_field_validation', function ( $result, $value, $form, $field ) {
	if ( ! $result['is_valid'] || strpos( (string) $field->cssClass, 'course-date' ) === false ) {
		return $result;
	}
	$dates = course_dates();
	if ( ! isset( $dates[ $value ] ) ) {
		return array( 'is_valid' => false, 'message' => 'Please choose a date from the list.' );
	}
	if ( course_date_taken( $form['id'], $field->id, $value ) >= $dates[ $value ]['seats'] ) {
		return array( 'is_valid' => false, 'message' => 'This date is full. Please choose another one.' );
	}
	return $result;
}, 10, 4 );

The field is a Drop Down with the CSS class course-date. The code finds it by that class, not by its ID, and its choices in the form settings stay empty. In the test, the form showed these two options:

Value Text
101 Pottery, January 12, 2027, 6:00 pm, Zurich (8 left)
102 Pottery, January 19, 2027, 6:00 pm, Zurich (1 left)

The seats left only appear in the form. For validation and submission, the same function writes the text without them, so the notification shows the date alone.

Why should the value be an ID and not the date?

An ID stays the same when you correct the text of a date, so every entry still belongs to its date. With the text as the value, entries made before a correction no longer match the date after it. In the test, the entry stored 102 in the date field, and the text came from the list.

The code counts the seats taken through the ID as well. GFAPI::count_entries "is used to get a count of all entries that match the given arguments" (documentation), here the active entries with the ID in the date field.

In Coursehall, the value of the Gravity Forms field is the ID of the session, and the text is course, date and location.

How is a full date rejected on submit?

gform_field_validation rejects the submission when the date is full or the value is not a date from the list. The documentation shows the result in the form array( 'is_valid' => false, 'message' => '…' ), and the message then stands at the field. The test ran in this order with made-up names:

Submission Result
Anna Muster picks 102 accepted, entry stored with 102
Ben Beispiel picks 102 rejected: "This date is full. Please choose another one.", no entry, no email
Carla Probe sends 999 rejected: "Please choose a date from the list.", no entry

After that, the form showed 102 as "(full)", and the form held one entry. The check counts stored entries. Two submissions for the last seat at the same moment were not part of this test; why that needs a lock is covered in a separate article.

In Coursehall, gform_field_validation rejects a full, canceled or foreign session.

What do notifications show instead of the value?

The merge tag of the field shows the text of the date, :value shows the ID. The documentation of field merge tags describes :value as "Displays the selected item's value." In the test, the notification with {Course date:3} and {Course date:3:value} read:

Name: Anna Muster
Date: Pottery, January 19, 2027, 6:00 pm, Zurich
Date ID: 102

That only holds if the field has its choices when the email is built. On the test installation, notifications ran in the background. Without the line with gform_form_pre_process_async_task, the same notification showed Date: 102. The documentation says the filter "can be used to modify the form object before notifications and add-on feeds are processed by the async (background) task processor". Background processing defaults to on for new installations since Gravity Forms 2.9.32, according to the documentation of gform_is_asynchronous_notifications_enabled.

In Coursehall, notifications show the text of the session field, never :value, because the value is an ID.

Which field names collide with Gravity Forms?

A field named gf_page collided in the test. A POST to admin-post.php without a query string that carried gf_page got HTTP 302 to wp-login.php. The same request with b5_gf_page instead got HTTP 400, which is how WordPress answers an action without a handler. With gf_page in the body and ?x=1 in the address, the answer was HTTP 400 as well.

We came across this on a settings page of our own: the form sent its fields with gf_page to admin-post.php, and saving stopped without a message until the fields had a prefix of their own. Give your own field names a prefix. The documentation of Gravity Forms does not mention gf_page; its site search returned no result on November 30, 2026.

How we measure and check is described on the method page. With Coursehall Pro, a Gravity Forms field gets its sessions this way, see course registration with Gravity Forms and the pricing.