J Simmons
J Simmons

Reputation: 57

Is it possible to send an array in a php header (like you can with a form)?

I am trying to make a dynamically sized form for a web-page I am creating! I have had no issue passing the information needed to the 'action' page through a form (including two arrays), by setting the name of all dynamically created forms to be name[i]. To get the data from the array in the 'action' file, I use the code below, and it works fine:

$_POST['name'][$i]

However, I wish to return the information to the form if there is an error with any of it, and the way I am doing this is with headers.

 header("Location: ../originalPage.php?error=error&someValue=".$someValue."&someArray[]=".$someArray);
 exit();

Is there anything I need to change for this to return something other than Array()? Clearly the header is using the $_GET method rather than the form's $_POST method, but why can I only send the array one way?!

Any help would be appreciated!

Upvotes: 1

Views: 244

Answers (1)

Lajos Arpad
Lajos Arpad

Reputation: 76905

The issue you have is that you try to concatenate your array to a string, but that does not happen in the way you would prefer. You could convert your array into JSON, like this:

 ../originalPage.php?error=error&someValue=".$someValue."&someArray[]=".json_encode($someArray));

Read more about json_encode by clicking on the link.

Upvotes: 1

Related Questions