It's much easier to filter out the empty fields on page2.php:
$_GET = array_filter($_GET);
That removes any empty $_GET
array entries.
If you absolutely have to do this before submitting to page2, you'll need to use client-side javascript to loop through all form fields and remove the ones that are empty. Not ideal.