Column 'form_id' cannot be null

When trying to submit on this form, the following error have popped up. Shouldn’t the form_id be grabbed automatically by Gravity Forms?
Other forms we have does not have this issue.

WordPress database error: [Column ‘form_id’ cannot be null]
INSERT INTO wp_gf_entry (form_id, ip, source_url, date_created, date_updated, user_agent, currency, created_by) VALUES (NULL, 'IP', 'URL', '2022-06-08 20:08:56', '2022-06-08 20:08:56', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36', 'USD', '10')

To add to the above comment, the following validation php is set to this form:

add_filter( 'gform_validation_23' , 'for_form23');

function for_form23 ($form){
	$id = rgpost("input_3");
	$requester_ip = rgpost("input_5");
	$requester_name = rgpost("input_6");
	GFCommon::log_debug(__METHOD__."(): id {$id}");
	GFCommon::log_debug(__METHOD__."(): ip {$requester_ip}");
	GFCommon::log_debug(__METHOD__."(): name {$requester_name}");
	
	$admins = array(*list of admins*);
	foreach ($admins as $admin){
		if ($requester_name == $admin){
			GFCommon::log_debug(__METHOD__."(): admincheck {$admin}{$requester_name}");
			$is_admin = 0;
			break;
		}
		else $is_admin = 1;
	}
	
	if ($is_admin == 0){
		//Something here
	}
	else if ($is_admin ==1){
		$form['is_valid'] = false;
  
        //finding Field with ID of 1 and marking it as failed validation
        foreach( $validation_result['fields'] as &$field ) {
  
            //NOTE: replace 1 with the field you would like to validate
            if ( $field->id == '6' ) {
                $field->failed_validation = true;
                $field->validation_message = 'Field Invalid';
                break;
            }
        }
	}
	$form['form'] = $validation_result;
	return $form;
}

The filter param and return value are incorrect. Try this:

add_filter( 'gform_validation_23' , 'for_form23');

function for_form23 ($validation_result){
	$form = $validation_result['form'];
	$id = rgpost("input_3");
	$requester_ip = rgpost("input_5");
	$requester_name = rgpost("input_6");
	GFCommon::log_debug(__METHOD__."(): id {$id}");
	GFCommon::log_debug(__METHOD__."(): ip {$requester_ip}");
	GFCommon::log_debug(__METHOD__."(): name {$requester_name}");
	
	$admins = array(*list of admins*);
	foreach ($admins as $admin){
		if ($requester_name == $admin){
			GFCommon::log_debug(__METHOD__."(): admincheck {$admin}{$requester_name}");
			$is_admin = 0;
			break;
		}
		else $is_admin = 1;
	}
	
	if ($is_admin == 0){
		//Something here
	}
	else if ($is_admin ==1){
		$validation_result['is_valid'] = false;
  
        //finding Field with ID of 1 and marking it as failed validation
        foreach( $form['fields'] as &$field ) {
  
            //NOTE: replace 1 with the field you would like to validate
            if ( $field->id == '6' ) {
                $field->failed_validation = true;
                $field->validation_message = 'Field Invalid';
                break;
            }
        }
	}
	$validation_result['form'] = $form;
	return $validation_result;
}
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.