Prevent post creation based on checkbox

Hello,

I am trying to prevent posts to be created if a certain checkbox is not checked in the form.
I feel like i’m very close with this code snippit from the docs:

add_filter( 'gform_disable_post_creation_6', 'disable_post_creation', 10, 3 );
function disable_post_creation( $is_disabled, $form, $entry ) {
    $is_disabled = rgar( $entry, '2' ) != 'something' ? true : $is_disabled;
    return $is_disabled;
}

The checkbox has only one option. So i tried something like $entry, ‘75.1’ != true
But i doesn’t work. Can somebody help me?
Form id is 18. Field ID is 75.

thanks!

Hi Jarno. For form 18 and field 75, if field 75 is a checkbox with just one checkbox, and the value of the checkbox is “No Post”, then this code will prevent the form from creating a post when that checkbox is checked:

// apply to form 18 only
add_filter( 'gform_disable_post_creation_18', 'disable_post_creation', 10, 3 );
function disable_post_creation( $is_disabled, $form, $entry ) {
	// field 75 checkbox #1
	// if the field is checked and the value is "No Post" then this will return true
	$is_disabled = rgar( $entry, '75.1' ) == 'No Post' ? true : $is_disabled;
	return $is_disabled;
}

Let me know if that does not work or if you need to do something different.

© 2008 - 2021. Gravity Forms is a project by Rocketgenius Inc.