Question

I have a basic form with a lot of input text boxes to fill:

<form action="page2.php" method="get">
<input type="text" name="a">
<input type="text" name="b">
...
<<input type="text" name="z">>
</form>

I want to pass to page2.php only filled input fields and ignore the rest. It seems simple but i can't figure it out...

Thanks!

Was it helpful?

Solution

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.

OTHER TIPS

In page2.php

use

foreach($_GET as $key => $value){
// This will extract those fields which dint have value.
}

Alternatively you can use jQuery / Javascript to iterate over input type text and send only those fields which have values in it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top