URL filter records with null value in a certain field

Sometimes its useful to be able to access all records where a certain field is empty.
For example if you want to email a reminder to users that they’ve some incomplete records.
PHPMaker doesn’t by default allow you to filter null values via URLYou override this by adding this to Recordset_Searching event of any table you want to all null searches:

foreach ($_GET as $key => $value) {
	// Check if the key starts with "x_" and the value is empty
	if (strpos($key, "x_") === 0 && $value === "") {
		// Extract the field name by removing the "x_" prefix
		$fieldName = substr($key, 2);
		// Apply the filter for NULL or empty string
		AddFilter($filter, "$fieldName IS NULL OR $fieldName = ''");
	}
}

After that use a URL like this:

MyTableList?cmd=search&x_myFieldname= // leave the end like this

updatedThe previous code broke normal searches. The code below will only allow null search if no other search parameters are given, which is ideal for a URL based filter:

		$hasOtherFilters = false;

			// Iterate through all GET parameters to check for other search criteria
			foreach ($_GET as $key => $value) {
				// Check if the key starts with "x_" or "z_" and the value is not empty
				if ((strpos($key, "x_") === 0 || strpos($key, "z_") === 0) && $value !== "") {
					$hasOtherFilters = true; // Set flag if any search criteria are present
					break; // No need to check further
				}
			}

			// If there are no other filters, check for empty search parameters
			if (!$hasOtherFilters) {
				foreach ($_GET as $key => $value) {
					// Check if the key starts with "x_" or "z_" and the value is empty
					if ((strpos($key, "x_") === 0 || strpos($key, "z_") === 0) && $value === "") {
						// Extract the field name by removing the prefix
						$fieldName = substr($key, 2);
						// Apply the filter for NULL or empty string
						AddFilter($filter, "$fieldName IS NULL OR $fieldName = ''");
					}
				}
			}