1

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!

5
  • 1
    So $someArray is itself an array? You can not concatenate arrays into strings like that, that will always only result in the word “Array”. You would need to access and append the individual, scalar values one by one. Commented Nov 10, 2020 at 14:39
  • 1
    But the real proper solution to your problem is likely php.net/manual/en/function.http-build-query.php Commented Nov 10, 2020 at 14:39
  • @CBroe Yes, $someArray is itself an array, and I wish to place this into the header as a single parameter, just like I did with the form to begin with. If the only way to do that is to append them individually, that's fine, I was just hoping there may be another way! Thanks for the help already though! Commented Nov 10, 2020 at 14:43
  • 2
    I just pointed you to what the proper way of handling this would be, did I not? You create the proper data structure that contains all the parameters you want to append to the URL query string, and then you let the mentioned function handle the rest. Commented Nov 10, 2020 at 14:47
  • @CBroe s method is pretty easy and smart. it will take you about 2 minutes to change your header, and make it work. Commented Nov 10, 2020 at 14:53

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.